wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance from inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance from inner Class" Watch "Inheritance from inner Class" New topic
Author

Inheritance from inner Class

Ahmad Mudassir
Greenhorn

Joined: Oct 16, 2000
Posts: 10
Hello !
My Question for the managers of this site
can we inherit a subclass from inner classes if yes than how?
the other question is what are the valid declaration of the inner classes as follows
2. Given:
public class OuterClass {
private double d1 = 1.0;
//insert code here
}
You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.)
class InnerOne{
public static double methoda() {return d1;}
}
public class InnerOne{
static double methoda() {return d1;}
}
private class InnerOne{
double methoda() {return d1;}
}
static class InnerOne{
protected double methoda() {return d1;}
}
abstract class InnerOne{
public abstract double methoda();
}
the third question is whether i have heard from a person given the exam that we also have to write code there e.g how to declare inner class etc.. (this was not in the exam).
waiting for the reply
Thanx
Ahmad
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I can answer number 2 for you. As with methods of classes, you can't access non-static variables with static methods. So with this in mind, you can not access non-static variables from static methods of inner classes either. Makes sense because you don't need an instance of the class to use a static method, so if you don't have an instance of the class, then what does the non-static variable refer to.
So with the above in mind, answer A,B,and D all use static methods and they are trying to access the non-static variable d.
 
 
subject: Inheritance from inner Class