Java Programming - Inner Classes - Discussion
Discussion Forum : Inner Classes - General Questions (Q.No. 3)
3.
Which is true about a method-local inner class?
Answer: Option
Explanation:
Option B is correct because a method-local inner class can be abstract, although it means a subclass of the inner class must be created if the abstract class is to be used (so an abstract method-local inner class is probably not useful).
Option A is incorrect because a method-local inner class does not have to be declared final (although it is legal to do so).
C and D are incorrect because a method-local inner class cannot be made public (remember-you cannot mark any local variables as public), or static.
Discussion:
15 comments Page 2 of 2.
Rakesh said:
1 decade ago
What is method -local inner classes?
Thirumal said:
1 decade ago
I think Option B is wrong. Can You explain with an example?
Mikhail said:
1 decade ago
Inner class can be abstract, final, private, protected.
Why only b is correct ?
Why only b is correct ?
Bisan said:
1 decade ago
Option B is the right answer as per the options available method-local inner class can be marked abstract or final.
Option A is wrong just because it said must in the statement as it is not mandatory to mark final.
Option A is wrong just because it said must in the statement as it is not mandatory to mark final.
Sasi said:
8 years ago
Static block, static variables and methods are called before object creation in order to initialize static data members, constructors are used to initializing instance data members. So before object creation, static block called. For inner classes no need of making static. That's is a reason for option D incorrect.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers