More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Core Java - Interview Questions and Answers for 'Static nested classes' - 3 question(s) found - Order By Newest
Q1. Which of the following can be marked static ?
a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes
Q2. Which of the following cannot be marked static ?
a. Constructors , Classes ( Outer ) , Classes ( nested ), Interfaces , Local variables , Inner Class methods and instance variables. b. Constructors , Classes ( Outer ) , Interfaces , Local variables , Class variables , Class Methods , Inner Class methods and instance variables. c. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables. d. Constructors , Classes ( Outer ) , Classes (Nested), Interfaces , Local variables , Inner Class methods and instance variables
Ans. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The accessibility (public, protected, etc.) of the static nested class is defined by the outer class.
A static nested class is not an inner class, it's a top-level nested class.
The name of the static nested class is expressed with OuterClassName.NestedClassName syntax.
When you define an inner nested class (or interface) inside an interface, the nested class is declared implicitly public and static.
Static nested classes can be declared abstract or final.
Static nested classes can extend another class or it can be used as a base class.
Static nested classes can have static members.
Static nested classes can access the members of the outer class (only static members, obviously).
The outer class can also access the members (even private members) of the nested class through an object of nested class. If you don't declare an instance of the nested class, the outer class cannot access nested class elements directly.
Help us improve. Please let us know the company, where you were asked this question :