• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Question about top-level nested class/static inner class

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,all
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andre,
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[code]
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(){
System.out.println(Outer.this.alpha);//-------------------(A)
}
}
//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)
}
[code]
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
[CODE]
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???
[CODE]

Thanks in Advance
 
I'm so happy! And I wish to make this tiny ad happy too:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic