Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 811–820 of 958
Topics in Java Programming
Q.811 Easy OOP in Java
Which concept best describes the relationship between Parent and Child classes in 'class Child extends Parent'?
A Composition
B Aggregation
C Inheritance
D Encapsulation
Correct Answer:  C. Inheritance
EXPLANATION

The 'extends' keyword creates an inheritance relationship where Child inherits properties and methods from Parent. This is an 'is-a' relationship.

Take Test
Q.812 Medium OOP in Java
Which of the following is true about abstract classes?
A They can have constructors
B They cannot have any concrete methods
C They must be instantiated directly
D They can only have abstract methods
Correct Answer:  A. They can have constructors
EXPLANATION

Abstract classes can have constructors to initialize instance variables. They can contain both abstract and concrete methods, and they cannot be directly instantiated.

Take Test
Q.813 Medium OOP in Java
What is method overloading?
A Defining multiple methods with different parameters but same name
B Defining multiple methods with same parameters and same name
C Creating methods in parent and child classes with same name
D Calling a method multiple times
Correct Answer:  A. Defining multiple methods with different parameters but same name
EXPLANATION

Method overloading allows multiple methods with the same name but different parameters (number, type, or order). It is a compile-time (static) polymorphism.

Take Test
Q.814 Medium OOP in Java
Consider:
interface I1 { void method(); }
interface I2 { void method(); }
class C implements I1, I2 { public void method() { System.out.println("Method"); } }
What will be the behavior?
A Compilation error due to ambiguity
B The single method implementation satisfies both interfaces
C Runtime error
D Only I1's method is implemented
Correct Answer:  B. The single method implementation satisfies both interfaces
EXPLANATION

When a class implements multiple interfaces with the same method signature, a single method implementation satisfies all interfaces. This is resolved at compile time.

Take Test
Q.815 Medium OOP in Java
Which statement about 'this' keyword is correct?
A It always refers to the parent class
B It refers to the current instance of the class
C It is used only in static methods
D It cannot be used in constructors
Correct Answer:  B. It refers to the current instance of the class
EXPLANATION

'this' is a reference variable that refers to the current object instance. It is commonly used to distinguish instance variables from parameters with the same name.

Take Test
Q.816 Medium OOP in Java
What will happen if you try to override a final method in a child class?
A It will compile successfully
B Compilation error will occur
C Runtime error will occur
D The final keyword will be ignored
Correct Answer:  B. Compilation error will occur
EXPLANATION

Final methods cannot be overridden. The compiler will throw an error indicating that you cannot override a final method.

Take Test
Q.817 Easy OOP in Java
Which access modifier allows a member to be accessed only within the same class?
A public
B private
C default
D protected
Correct Answer:  B. private
EXPLANATION

The 'private' access modifier restricts access to only the members of the same class. It provides the highest level of encapsulation.

Take Test
Q.818 Easy OOP in Java
Consider the code:
class A { A() { System.out.println("A"); } }
class B extends A { B() { super(); System.out.println("B"); } }
What will be printed when 'new B()' is executed?
A B then A
B A then B
C Only B
D Compilation Error
Correct Answer:  B. A then B
EXPLANATION

The super() call invokes the parent class constructor first, printing 'A', then the child constructor completes, printing 'B'.

Take Test
Q.819 Easy OOP in Java
What is the primary purpose of the 'super' keyword in Java?
A To create an instance of the parent class
B To access parent class methods and constructors
C To declare a variable as final
D To implement multiple inheritance
Correct Answer:  B. To access parent class methods and constructors
EXPLANATION

The 'super' keyword is used to refer to parent class methods, constructors, and variables. It allows a child class to access parent class members.

Take Test
Q.820 Medium OOP in Java
Which of the following is NOT a characteristic of an interface in Java?
A Can have abstract methods
B Can have static final variables
C Can have private instance variables (Java 9+)
D Can extend multiple interfaces
Correct Answer:  C. Can have private instance variables (Java 9+)
EXPLANATION

Interfaces cannot have instance variables (private or otherwise). They can only have constants (static final). Java 9+ allows private methods but not private instance variables.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips