Site icon DataFlair

Quiz on Java Inner Class

quiz on java inner class

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.

Time limit: 0

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

Quiz complete. Results are being recorded.

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

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. 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();

    }

    }

    Correct
    Incorrect
  2. 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();

    }

    }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    Which of the following is the correct syntax for static nested class ?

    Correct
    Incorrect
  4. 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 ?

    Correct
    Incorrect
  5. 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());

    }

    }

    Correct
    Incorrect
  6. 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();

    }

    }

    Correct
    Incorrect
  7. 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();   

       }

    }

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    Which of the following Inner  classes can be accessed without instantiating the outer class ?

    Correct
    Incorrect
  9. 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 ?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following is not true about static inner classes ?

    Correct
    Incorrect
  11. 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();

    }

    }

    Correct
    Incorrect
  12. 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();

    } }

    Correct
    Incorrect
  13. 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();

    }

    Correct
    Incorrect
  14. 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 );

    }

    }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    Which of the following is the correct syntax for declaring anonymous inner classes ?

    Correct
    Incorrect

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!

Exit mobile version