Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

1. Which of the following is NOT true about abstract classes in Java?

View

2. What happens if an interface has a method with a body in Java 8 or later?

View

3. Consider the following code. What will happen when main is executed?

View

4. Can an interface extend multiple interfaces? If so, how does it resolve conflicts in methods?

View

5. What will be the output of the following code?

View

6. Which of the following is NOT allowed in an interface?

View

7. Why is multiple inheritance through classes not allowed in Java, but allowed through interfaces?

View

8. What is the difference between abstract classes and interfaces?

View

9. Consider the code below. What will happen?

View

10. Which of the following is a valid way to achieve partial abstraction in Java?

View

1. Which of the following is NOT true about abstract classes in Java?

Abstract classes can have constructors.
Abstract classes cannot have non-abstract methods.
An abstract class cannot be instantiated directly.
Abstract classes can implement interfaces.

2. What happens if an interface has a method with a body in Java 8 or later?

<p>A. Compilation error.</p><p>B. The method must be declared as default or static.</p><p>C. The interface is treated as an abstract class.</p><p>D. The method must be declared as protected.<br><strong>Answer:</strong> B</p>

Compilation error.
The method must be declared as default or static.
The interface is treated as an abstract class.
The method must be declared as protected.

3. Consider the following code. What will happen when main is executed?

<p>abstract class A {<br>&nbsp; &nbsp; abstract void display();<br>&nbsp; &nbsp; void show() {<br>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Abstract class method");<br>&nbsp; &nbsp; }<br>}<br>class B extends A {<br>&nbsp; &nbsp; void display() {<br>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Overridden abstract method");<br>&nbsp; &nbsp; }<br>}<br>public class Test {<br>&nbsp; &nbsp; public static void main(String[] args) {<br>&nbsp; &nbsp; &nbsp; &nbsp; A obj = new B();<br>&nbsp; &nbsp; &nbsp; &nbsp; obj.display();<br>&nbsp; &nbsp; &nbsp; &nbsp; obj.show();<br>&nbsp; &nbsp; }<br>}<br><br></p>

Compilation error.
Outputs "Overridden abstract method" followed by "Abstract class method".
Outputs "Abstract class method" only.
Runtime error.

4. Can an interface extend multiple interfaces? If so, how does it resolve conflicts in methods?

Yes, but conflicts are resolved by implementing class.
No, interfaces cannot extend multiple interfaces.
Yes, and conflicts are resolved by the first listed interface.
Conflicts are resolved automatically by Java

5. What will be the output of the following code?

<p>interface A {<br>&nbsp; &nbsp; default void display() {<br>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Interface A");<br>&nbsp; &nbsp; }<br>}<br>interface B {<br>&nbsp; &nbsp; default void display() {<br>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Interface B");<br>&nbsp; &nbsp; }<br>}<br>class C implements A, B {<br>&nbsp; &nbsp; public void display() {<br>&nbsp; &nbsp; &nbsp; &nbsp; A.super.display();<br>&nbsp; &nbsp; &nbsp; &nbsp; B.super.display();<br>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Class C");<br>&nbsp; &nbsp; }<br>}<br>public class Test {<br>&nbsp; &nbsp; public static void main(String[] args) {<br>&nbsp; &nbsp; &nbsp; &nbsp; C obj = new C();<br>&nbsp; &nbsp; &nbsp; &nbsp; obj.display();<br>&nbsp; &nbsp; }<br>}<br><br></p>

Interface A followed by Class C.
Interface A followed by Interface B and then Class C.
Compilation error due to ambiguity.
Runtime error.

6. Which of the following is NOT allowed in an interface?

Abstract methods.
Default methods.
Static methods.
Private constructors.

7. Why is multiple inheritance through classes not allowed in Java, but allowed through interfaces?

<p><br></p><p><br></p>

To prevent ambiguity from the diamond problem.
Interfaces cannot have concrete methods.
Interfaces are implemented, not extended.
None of the above.

8. What is the difference between abstract classes and interfaces?

Abstract classes allow constructors, while interfaces do not.
Interfaces can have fields, while abstract classes cannot.
Both must be instantiated directly.
Abstract classes cannot implement other classes.

9. Consider the code below. What will happen?

<p>interface A {<br>&nbsp; &nbsp; void show();<br>}<br>abstract class B implements A {<br>&nbsp; &nbsp; void display() {<br>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Abstract class method");<br>&nbsp; &nbsp; }<br>}<br>class C extends B {<br>&nbsp; &nbsp; void show() {<br>&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Interface method implemented");<br>&nbsp; &nbsp; }<br>}<br>public class Test {<br>&nbsp; &nbsp; public static void main(String[] args) {<br>&nbsp; &nbsp; &nbsp; &nbsp; C obj = new C();<br>&nbsp; &nbsp; &nbsp; &nbsp; obj.show();<br>&nbsp; &nbsp; &nbsp; &nbsp; obj.display();<br>&nbsp; &nbsp; }<br>}<br><br></p>

Compilation error due to B not implementing show().
Outputs "Interface method implemented" followed by "Abstract class method".
Outputs "Abstract class method" only.
Runtime error.

10. Which of the following is a valid way to achieve partial abstraction in Java?

Using abstract classes.
Using interfaces with default methods.
Using a combination of abstract classes and interfaces.
All of the above.