Inner Classes Questions
Practice Inner Classes MCQs with answers and explanations. Page 1 of 1.
Category
Java Programming
Topic
Inner Classes
Page
1 / 1
Mode
Practice
Questions
Open any question to view the answer and explanation.
Java — Create an instance of a non-static member inner class from outside its outer class:
class Foo
{
class Bar { }
}
class Test
{
public static void main (String [] args)
{
Foo f = new Foo();
/* Line 10: Missing statement? */
}
}
Open
View answer
Java — Identify which statements actually construct an anonymous inner class instance (Runnable example)
Open
View answer
Java — Create an anonymous inner class instance within a subclass method:
class Boo
{
Boo(String s) { }
Boo() { }
}
class Bar extends Boo
{
Bar() { }
Bar(String s) { super(s); }
void zoo()
{
// insert code here
}
}
Open
View answer
Java — Truths about anonymous inner classes (capabilities and limitations)
Open
View answer
Java — Properties of a method-local inner class (what modifiers are allowed?)
Open
View answer
In Java, consider the following nested type:
public class MyOuter
{
public static class MyInner
{
public static void foo() { }
}
}
Which statement, when written from some other class (not MyOuter or MyInner), correctly instantiates the static nested class MyOuter.MyInner?
Open
View answer
In Java, which statement about a static nested class is correct?
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.