Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Ready to dive deeper into the intricacies of Java inner classes? Take your knowledge to the next level with this comprehensive quiz! Designed to challenge both beginners and experienced Java programmers, these questions will test your understanding of inner class syntax, behavior, and their effective use in various programming scenarios.
Get ready to explore access modifiers, object creation, method calls, and more as you navigate through this interactive learning experience. Let’s test your knowledge.
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 15
1. Question
class OuterClass {
String absolute;
private class InnerClass {
void message() {
System.out.println(“DataFlair”);
}
}
void displayInnerMessage() {
InnerClass obj = new InnerClass();
obj.message();
}
}
public class MainClass {
public static void main ( String args [ ] )
{
OuterClass object = new OuterClass();
object.displayInnerMessage();
}
}
CorrectIncorrect -
Question 2 of 15
2. Question
class OuterSample {
class InnerClass {
void text () {
System.out.println(“This Message is from the Inner class”);
}
}
void printMethod() {
InnerClass obj = new InnerClass();
}
}
public class MainClass {
public static void main ( String args [ ] )
{
MainClass object = new MainClass():
object.printMethod();
}
}
CorrectIncorrect -
Question 3 of 15
3. Question
Which of the following is the correct syntax for static nested class ?
CorrectIncorrect -
Question 4 of 15
4. Question
Which of the following is the correct method to access the private members of a class from another class ?
CorrectIncorrect -
Question 5 of 15
5. Question
class OuterClass {
private String data = “DataFlair”;
class InnerClassExample {
private getText() {
return data;
}
}
public class MainClass {
public static void main ( String args [ ] )
{
OuterClass obj = new OuterClass();
OuterClass.InnerClassExample object = obj.InnerClassExample();
System.out.println(object.getText());
}
}
CorrectIncorrect -
Question 6 of 15
6. Question
class OuterClass {
String text = “DataFlair”;
void printMessage() {
class InnerClass {
void display() {
System.out.println(text);
}
}
InnerClass obj = new InnerClass();
obj.display();
}
}
class MainClass {
public static void main ( String args [ ] )
{
OuterClass object = new outerClass();
object.printMessage();
}
}
CorrectIncorrect -
Question 7 of 15
7. Question
abstract class AnonymousExample {
public abstract void printMethod();
}
public class Outer {
public static void main ( String args [ ] )
{
AnonymousExample obj = new AnonymousExample() {
public void printMethod() {
System.out.println(“This is an example of anonymous inner class”);
}
};
obj.printMethod();
}
}
CorrectIncorrect -
Question 8 of 15
8. Question
Which of the following Inner classes can be accessed without instantiating the outer class ?
CorrectIncorrect -
Question 9 of 15
9. Question
interface text {
String Data;
}
public class OuterClass {
void printMessage ( text t ) {
System.out.println(t.Data);
}
public static void main ( String args [ ] )
{
OuterClass obj = new OuterClass();
obj.printMessage(new text() {
public String Data ( ) {
Return “DataFlair”:
} });
}
}
What will be the output of the given program ?
CorrectIncorrect -
Question 10 of 15
10. Question
Which of the following is not true about static inner classes ?
CorrectIncorrect -
Question 11 of 15
11. Question
class Outer {
private String text = “Data”;
class Inner {
String message = “Flair”;
void printData() {
System.out.println(text+message);
}
}
public static void main ( String args [ ] )
{
Outer obj = new Outer();
Outer.Inner Object = obj Inner();
object.printData();
}
}
CorrectIncorrect -
Question 12 of 15
12. Question
abstract class Program {
void output();
}
class AnonymousSample {
Public static void main ( String args [ ] )
{
Program obj = new Program();
void output ( ) {
System.out.println(“Output is printed”);
}
};
obj.output();
} }
CorrectIncorrect -
Question 13 of 15
13. Question
class OuterExample {
private int a = 8;
void displayNumber ( ) {
class Inner {
void display ( ) {
system.out.println(“The number is “ + a );
}
}
};
public static void main ( String args [ ] )
{
Inner obj = new Inner();
obj.display();
Outer object = new Outer () ;
object.displayNumber();
}
CorrectIncorrect -
Question 14 of 15
14. Question
class OuterSample {
int a = 3;
class InnerSample {
int b = 3;
}}
public class MainClass {
public static void main(String args [ ] ) {
OuterSample object1 = new OuterSample();
OuterSample.InnerSample object2 = object1.new InnerSample();
System.out.println( object1.a * object2.b );
}
}
CorrectIncorrect -
Question 15 of 15
15. Question
Which of the following is the correct syntax for declaring anonymous inner classes ?
CorrectIncorrect
Summary:
Congratulations on completing this Java inner class quiz! By now, you should have a clearer understanding of how inner classes work, when to use them effectively, and common pitfalls to avoid.
Remember, consistent practice is key to mastering any programming concept. Continue exploring Java’s inner workings, and don’t hesitate to revisit this quiz or seek out additional resources to solidify your knowledge. Stay curious, keep coding, and unleash the power of inner classes in your Java projects!
