iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

951 questions | 100% Free

Q.101Medium

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); } }

Q.102Easy

Which access modifier allows a member to be accessed only within the same package?

Q.103Easy

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();

Q.104Medium

Which of the following statements about abstract classes is TRUE?

Q.105Easy

What is the purpose of the 'super' keyword in Java?

Q.106Easy

Which interface in Java represents a collection that does not allow duplicate elements?

Q.107Medium

What will happen when you try to instantiate an interface in Java?

Q.108Medium

Which of the following best describes encapsulation?

Q.109Medium

Which of the following is true about method overloading?

Q.110Medium

What is the correct way to prevent a class from being inherited in Java?

Q.111Hard

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();

Q.112Easy

Which of the following correctly describes the 'this' keyword?

Q.113Medium

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(); } }

Q.114Easy

Which keyword is used to make a variable immutable in Java?

Q.115Hard

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); } }

Q.116Medium

Which of the following statements about 'instanceof' operator is correct?

Q.117Hard

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(); } }

Q.118Easy

Which of the following access modifiers allows a variable to be accessed only within the same class?

Q.119Easy

In Java, which keyword is used to create a reference variable that cannot point to a different object after initialization?

Q.120Medium

Which of the following statements about inheritance in Java is correct?