How do I access methods inside of a nested class?
Say I have this code...
public class SuperClass {
// nested class
public class InnerClass{
public boolean isTrue(){
return boolean;
}
}
}
public class SubClass extends SuperClass{
// stuff
}
public class Tester {
SubClass object = new SubClass();
// How do I make the following line work?
System.out.println(object.isTrue());
}
Thanks.
[549 byte] By [
srekcus] at [2007-11-11 8:10:50]

# 1 Re: How do I access methods inside of a nested class?
As far as I know, you can't. Nor can you access that method if you created an instance of SuperClass. The only way that you can access that method is if you create an instance of InnerClass.
destin at 2007-11-11 22:36:12 >

# 2 Re: How do I access methods inside of a nested class?
I can create an instance of InnerClass from inside Super or Sub class, but not the Tester class. I need to if there is any way to either create an instance of InnerClass from within Tester, or to simply access its methods.
# 3 Re: How do I access methods inside of a nested class?
public class Tester {
SuperClass.InnerClass object = new SuperClass().new InnerClass();
SubClass.InnerClass object2 = new SubClass().new InnerClass();
public void myTest1() {
// How do I make the following line work?
System.out.println(object.isTrue());
System.out.println(object2.isTrue());
}
public static void main(String[] args) {
new Tester().myTest1();
}
}
public class SuperClass {
// nested class
public class InnerClass{
public boolean isTrue(){
boolean isTrue = false;
return isTrue;
}
}
}
public class SubClass extends SuperClass{
// stuff
}
Your nested class is non-static, so it is only meaningful in the instance of your outer class. Hope this helps.
arul at 2007-11-11 22:38:16 >
