• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Question about top-level nested class/static inner class

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's the question
Which of these statements concerning nested classes are true?
Select all valid answers.
a. An instance of a top-level nested class has an inherent outer instance.
b. A top-level nested class can contain non-static member variables.
c. A top-level nested interface can contain non-static member variables.
d. A top-level nested interface has an inherent outer instance.
e. For each instance of the outer class, there can exist many instances of a non-static inner class.
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only b & e are true. We need to clarify the terminology here.
I assume top-level nested class means "static" nested class
per JLS.
a) is false, since top-level nested class, i.e static nested
class has no enclosing instance, just like any non nested
top level class.
b) is true. In fact, it can have both static and non-static
member variables.
c) is false, because member variable in an interface is
implicitly "static". In fact, they are public static final.
d) is false, for the same reason as a
e) is true, for obvious reason.
[This message has been edited by Nain Hwu (edited December 13, 2001).]
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Outer{
public String alpha="Instance Variable of Outer Class";
Outer(){} //works with any modifier public,private,protected
void Outer(String s){}
//Constructors can't be native, abstract, static, synchronized, or final:
class Inner{
void print(){
//class Inner3 extends Inner{} cannot be possible
static class Inner4{ //works fine
public void method(){
Inner4 ref=new Inner4(); //can do only in static class methods -----------------(B)
//class static Inner4{} //does not--------------(C)
Question 1
plz expalin A,B,C correct me if i am wrong
Question 2
What type of Exception an Inner class can throw or may occur in Inner Class
Question no 3
class Outer{
class static Inner{}
How will you create an instance of static Inner Class? Select 2
a. Inner a= new Inner();
b. Outer o= new Outer();Outer.Inner a= new o.Inner();
c. Outer.Inner a= new Outer.new Inner();
d. Outer.Inner a= new Outer.Inner();
ANS is B,D but A also in a method of Static class???

Thanks in Advance
    Bookmark Topic Watch Topic
  • New Topic