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?
2. What happens if an interface has a method with a body in Java 8 or later?
3. Consider the following code. What will happen when main is executed?
4. Can an interface extend multiple interfaces? If so, how does it resolve conflicts in methods?
5. What will be the output of the following code?
6. Which of the following is NOT allowed in an interface?
7. Why is multiple inheritance through classes not allowed in Java, but allowed through interfaces?
8. What is the difference between abstract classes and interfaces?
9. Consider the code below. What will happen?
10. Which of the following is a valid way to achieve partial abstraction in Java?
1. Which of the following is NOT true about abstract classes in Java?
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>
3. Consider the following code. What will happen when main is executed?
<p>abstract class A {<br> abstract void display();<br> void show() {<br> System.out.println("Abstract class method");<br> }<br>}<br>class B extends A {<br> void display() {<br> System.out.println("Overridden abstract method");<br> }<br>}<br>public class Test {<br> public static void main(String[] args) {<br> A obj = new B();<br> obj.display();<br> obj.show();<br> }<br>}<br><br></p>
4. Can an interface extend multiple interfaces? If so, how does it resolve conflicts in methods?
5. What will be the output of the following code?
<p>interface A {<br> default void display() {<br> System.out.println("Interface A");<br> }<br>}<br>interface B {<br> default void display() {<br> System.out.println("Interface B");<br> }<br>}<br>class C implements A, B {<br> public void display() {<br> A.super.display();<br> B.super.display();<br> System.out.println("Class C");<br> }<br>}<br>public class Test {<br> public static void main(String[] args) {<br> C obj = new C();<br> obj.display();<br> }<br>}<br><br></p>
6. Which of the following is NOT allowed in an interface?
7. Why is multiple inheritance through classes not allowed in Java, but allowed through interfaces?
<p><br></p><p><br></p>
8. What is the difference between abstract classes and interfaces?
9. Consider the code below. What will happen?
<p>interface A {<br> void show();<br>}<br>abstract class B implements A {<br> void display() {<br> System.out.println("Abstract class method");<br> }<br>}<br>class C extends B {<br> void show() {<br> System.out.println("Interface method implemented");<br> }<br>}<br>public class Test {<br> public static void main(String[] args) {<br> C obj = new C();<br> obj.show();<br> obj.display();<br> }<br>}<br><br></p>