7:00 am - Monday November 19, 2018

Inner Class Interview Question

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Inner Class Interview Question

1. What is inner class?

If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.

2. What is nested class?

If all the methods of a inner class is static then it is a nested class.

3. What are different types of inner classes?

Nested top-level classes, Member classes, Local classes, Anonymous classes

4.What is Nested top-level classes?

If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class.Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety.

5.What is Member classes?

Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.

6.What is Local classes?

Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement amore publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.

7.What is Anonymous classes?

Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.

8. Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbolsymbol : class ABCD, location: package io ,import java.io.ABCD;

 

                         

Filed in: Z-A Interview Questions

No comments yet.

Leave a Reply