Given below the sample code :
class SuperClass {
SuperClass() {
}
public class SubClass {
SubClass() {
}
}
}
Which is the correct way to declare the object of public "Subclass" , which can be use outside the "Superclass" ?
1. SubClass Sub = new SuperClass().new SubClass();
2. SubClass Sub = new SuperClass.SubClass();
3. SuperClass.SubClass Sub = new SuperClass.SubClass();
4. SuperClass.SubClass nbc = new SuperClass().new SubClass();
(4)
If the "Superclass" is declared as "static" it will be declared like this :
SuperClass.SubClass Sub = new SuperClass.SubClass();
But if the "Superclass" is declared as "public" it will be declared like this :
SuperClass.SubClass nbc = new SuperClass().new SubClass();
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.