File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance from inner Class

 
Ahmad Mudassir
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1070
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic