Java Programming - MCQ Practice Questions
Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.
958 questions | 100% Free
Which of the following is NOT a pillar of Object-Oriented Programming?
What is the output of the following code? class A { int x = 10; } class B extends A { int x = 20; } public class Test { public static void main(String[] args) { A obj = new B(); System.out.println(obj.x); } }
Which access modifier allows a member to be accessed only within the same package?
What will be the output? class Parent { void show() { System.out.println("Parent"); } } class Child extends Parent { void show() { System.out.println("Child"); } } parent obj = new Child(); obj.show();
Which of the following statements about abstract classes is TRUE?
What is the purpose of the 'super' keyword in Java?
Which interface in Java represents a collection that does not allow duplicate elements?
What will happen when you try to instantiate an interface in Java?
Which of the following best describes encapsulation?
Which of the following is true about method overloading?
What is the correct way to prevent a class from being inherited in Java?
What will be the output? interface A { void show(); } class B implements A { public void show() { System.out.println("B"); } } class C extends B { public void show() { System.out.println("C"); } } A obj = new C(); obj.show();
Which of the following correctly describes the 'this' keyword?
What is the output? class A { A() { System.out.println("A"); } } class B extends A { B() { super(); System.out.println("B"); } } public class Test { public static void main(String[] args) { new B(); } }
Which keyword is used to make a variable immutable in Java?
What will be the output? class Test { int x = 5; { x = 10; } Test() { x = 15; } public static void main(String[] args) { Test t = new Test(); System.out.println(t.x); } }
Which of the following statements about 'instanceof' operator is correct?
What is the output? interface I1 { void method1(); } interface I2 extends I1 { void method2(); } class C implements I2 { public void method1() { System.out.println("M1"); } public void method2() { System.out.println("M2"); } } public class Test { public static void main(String[] args) { I1 obj = new C(); obj.method2(); } }
Which of the following access modifiers allows a variable to be accessed only within the same class?
In Java, which keyword is used to create a reference variable that cannot point to a different object after initialization?