Home Tutorial Java Scjp Part3 SCJP Module-3 Question-5

 
 

Share on Google+Share on Google+
SCJP Module-3 Question-5
Posted on: July 12, 2010 at 12:00 AM
Advertisement
The class given below tests your understanding of classes and their objects initialization.

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();

Answer :

(4)

Explanation :

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();

Advertisement

Related Tags for SCJP Module-3 Question-5:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 12, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com