Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 401–410 of 476
Topics in Java Programming
Q.401 Medium OOP in Java
Which statement is true about the default access modifier (package-private) in Java?
A Members are accessible from any package
B Members are accessible only within the same package
C Members are accessible only within the same class
D Members are not accessible anywhere
Correct Answer:  B. Members are accessible only within the same package
EXPLANATION

The default (package-private) access modifier allows access to members from any class within the same package, but not from classes in other packages.

Take Test
Q.402 Medium OOP in Java
Consider the code:
abstract class Animal { abstract void sound(); void sleep() { System.out.println("Zzz"); } }
class Dog extends Animal { void sound() { System.out.println("Bark"); } }
What can Dog objects do?
A Only call sound()
B Only call sleep()
C Call both sound() and sleep()
D Neither sound() nor sleep()
Correct Answer:  C. Call both sound() and sleep()
EXPLANATION

Dog inherits the concrete method sleep() from Animal and provides implementation for the abstract method sound(). Therefore, Dog objects can call both methods.

Take Test
Q.403 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.404 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.405 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.406 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.407 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.408 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
Q.409 Medium OOP in Java
Which statement about the 'protected' access modifier is correct?
A It allows access only within the same package
B It allows access within the same package and by subclasses in different packages
C It is equivalent to 'private'
D It allows access globally like 'public'
Correct Answer:  B. It allows access within the same package and by subclasses in different packages
EXPLANATION

'protected' members are accessible within the same package and also to subclasses in different packages. It provides more access than default but less than public.

Take Test
Q.410 Medium OOP in Java
Which statement about interface implementation in Java is true?
A An interface can contain only abstract methods and no variables
B From Java 8 onwards, interfaces can have default methods and static methods
C A class implementing an interface must implement all its methods
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
EXPLANATION

Java 8 introduced default and static methods in interfaces. Any class implementing an interface must provide implementations for all its abstract methods (unless the implementing class is abstract).

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