The document contains 5 questions related to Java interfaces, inheritance, abstract classes and methods:
1. It asks the reader to fill in blanks to make a Point class implement a Shape interface with 2 missing method declarations.
2. It asks the reader to trace the execution of a program using inheritance and constructor chaining between classes B and D.
3. It asks the reader to predict the output of a program demonstrating inheritance and overriding between classes A and B.
4. It asks the reader true/false questions about the differences between interfaces and abstract classes.
5. It provides a code sample with errors implementing an interface and extending an abstract class, asking the reader to identify the problem.
The document contains 5 questions related to Java interfaces, inheritance, abstract classes and methods:
1. It asks the reader to fill in blanks to make a Point class implement a Shape interface with 2 missing method declarations.
2. It asks the reader to trace the execution of a program using inheritance and constructor chaining between classes B and D.
3. It asks the reader to predict the output of a program demonstrating inheritance and overriding between classes A and B.
4. It asks the reader true/false questions about the differences between interfaces and abstract classes.
5. It provides a code sample with errors implementing an interface and extending an abstract class, asking the reader to identify the problem.
The document contains 5 questions related to Java interfaces, inheritance, abstract classes and methods:
1. It asks the reader to fill in blanks to make a Point class implement a Shape interface with 2 missing method declarations.
2. It asks the reader to trace the execution of a program using inheritance and constructor chaining between classes B and D.
3. It asks the reader to predict the output of a program demonstrating inheritance and overriding between classes A and B.
4. It asks the reader true/false questions about the differences between interfaces and abstract classes.
5. It provides a code sample with errors implementing an interface and extending an abstract class, asking the reader to identify the problem.
The document contains 5 questions related to Java interfaces, inheritance, abstract classes and methods:
1. It asks the reader to fill in blanks to make a Point class implement a Shape interface with 2 missing method declarations.
2. It asks the reader to trace the execution of a program using inheritance and constructor chaining between classes B and D.
3. It asks the reader to predict the output of a program demonstrating inheritance and overriding between classes A and B.
4. It asks the reader true/false questions about the differences between interfaces and abstract classes.
5. It provides a code sample with errors implementing an interface and extending an abstract class, asking the reader to identify the problem.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 4
Question 1 : Interface
Fill in the blanks to make the program below run successfully.
interface Shape {
______________________ ______________________ }
public class Point implements Shape {
static int x, y; public Point() { x = 0; y = 0; } public double area() { return 0; } public double volume() { return 0; } public static void print() { System.out.println("point: " + x + "," + y); } public static void main(String args[]) { Point p = new Point(); p.print(); } }
Question 2 : Inheritance , Constructor chaining Trace the execution of the following program: class B { public B() { } public void p() { System.out.println("Big"); } }
class D extends B { public D() {} public void p() { super.p(); System.out.println("Deep"); } }
public class Try { public static void main(String[] args) { B b = new B(); D d = new D(); b.p(); d.p(); b = d; b.p(); }
} Big Big Deep Big Deep Question 3 : Inheritance, Objects and Methods What's the output of the program after you compile it and run it? Explain how that happens. class A { void fun() { System.out.println("Defined in A"); } }
class B extends A { void fun() { System.out.println("Defined in B"); } }
public class Two { public static void main(String[] args) { B me = new B(); A you = new B(); me.fun(); you.fun();
} }
Question 4 : Interface vs. Abstract Class All methods of an Interface are abstract methods while some methods of an Abstract class are abstract methods (True/False) Abstract methods of abstract class have abstract modifier (True/False) An interface can only define constants while abstract class can have fields . (True/False)
Question 5 : Interface and Abstract Class interface A { void displayA(); }
abstract class B { public void displayB() { System.out.println("Display-B"); }
abstract public void display(); } class C extends B implements A { public void displayB() { System.out.println("Abstract Display-B"); }
public void displayA() { System.out.println("Display-A"); } }
public class TestClass { public static void main(String args[]) { C obj=new C(); obj.display(); obj.displayA(); obj.displayB(); } }
What wrong with the above program ? Main.java:16: error: c is not abstract and does not override abstract method displayd() in A class c extends B implements A