Question 1 of 25
Hints left: 3
Q1
What is the result of the following code snippet? abstract class MyAbstract { abstract void myMethod(); } class MyClass extends MyAbstract { void myMethod() { System.out.println("Implementation"); } public static void main(String[] args) { MyAbstract obj = new MyClass(); obj.myMethod(); } }
Q2
In Java, can an interface extend another interface?
Q3
What is an interface in Java?
Q4
In Java, can a class implement multiple interfaces?
Q5
What is the purpose of the "extends" keyword in Java?
Q6
What will be the output of the following Java program? class A { int i; public void display() { System.out.println(i); } } class B extends A { int j; public void display() { System.out.println(j); } } class Dynamic_dispatch { public static void main(String args[]) { B obj2 = new B(); obj2.i = 1; obj2.j = 2; A r; r = obj2; r.display(); } }
Q7
What will be the output of the following Java code? class test { int a; int b; void meth(int i , int j) { i *= 2; j /= 2; } } class Output { public static void main(String args[]) { test obj = new test(); int a = 10; int b = 20; obj.meth(a , b); System.out.println(a + " " + b); } }
Q8
Which keyword is used to declare an interface in Java?
Q9
Which of the following can contain both abstract and non-abstract methods?
Q10
In Java, can an abstract class be instantiated?
Q11
What is the result of the following code snippet? interface MyInterface { void myMethod(); } public class MyClass implements MyInterface { public void myMethod() { System.out.println("Implementation"); } public static void main(String[] args) { MyInterface obj = new MyClass(); obj.myMethod(); } }
Q12
In Java, can an interface have fields (member variables)?
Q13
Which keyword is used to define an abstract method in Java?
Q14
What is the purpose of the "default" keyword in Java interfaces?
Q15
In Java, can an interface have private methods with implementations?
Q16
Which of this keyword can be used in a subclass to call the constructor of superclass?
Q17
What is the purpose of an abstract class in Java?
Q18
What is the purpose of the "implements" keyword in Java?
Q19
What will be the output of the following Java program? class Abc { public static void main(String[]args) { String[] elements = { "for", "tea", "too" }; String first = (elements.length > 0) ? elements[0]: null; } }
Q20
In Java, can an abstract class extend another class?
Q21
What is the result of the following code snippet? interface MyInterface { default void myMethod() { System.out.println("Default Implementation"); } } class MyClass implements MyInterface { public static void main(String[] args) { MyInterface obj = new MyClass(); obj.myMethod(); } }
Q22
At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among "final, static, native, public, private, abstract, protected" public interface Status { /* insert qualifier here */ int MY_VALUE = 10; }
Q23
What is the purpose of an abstract method in an abstract class or interface?
Q24
In Java, can an abstract class have non-abstract methods?
Q25
Which of these can be overloaded?