Question 1
What will be the output of this program?
abstract class Parent {
abstract void show();
}
class Child extends Parent {
void show() {
System.out.println("Child class method");
}
}
public class Main {
public static void main(String[] args) {
Parent p = new Child();
p.show();
}
}
Compilation Error
Runtime Error
Child class method
No Output
Question 2
What happens if an abstract class does not have any abstract methods?
It will not compile.
The class can still be abstract.
Java will automatically provide an abstract method.
It becomes a concrete class.
Question 3
What will be the output of this code?
class Animal {
void makeSound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
void makeSound() {
System.out.println("Dog barks");
}
}
public class Main {
public static void main(String[] args) {
Animal a = new Dog();
a.makeSound();
}
}
Animal makes a sound
Dog barks
Compilation error
Runtime error
Question 4
Which of the following statements about inheritance is false?
Java supports single inheritance.
Java allows multiple class inheritance using extends.
Interfaces can be used to achieve multiple inheritance.
The super keyword can be used to invoke the parent class constructor.
Question 5
Which of the following statements about abstract classes is correct?
Abstract classes cannot have constructors.
Abstract classes cannot have static methods.
An object of an abstract class cannot be instantiated.
Abstract classes cannot have final methods.
Question 6
In Java, we can make a class abstract by
Declaring it abstract using the abstract
keyword.
Making at least one method final
.
Declaring all methods as static
.
Declaring at least one method as abstract
.
Question 7
Which of the following is true about an abstract class in Java?
An abstract class can be instantiated directly.
An abstract class can contain both abstract and non-abstract methods.
All methods in an abstract class must be abstract.
An abstract class cannot have a constructor.
Question 8
Type IV JDBC driver is a driver
which is written in C++
which requires an intermediate layer
which communicates through Java sockets
which translates JDBC function calls into API not native to DBMS
Question 9
Predict the output of the following program.
abstract class demo
{
public int a;
demo()
{
a = 10;
}
abstract public void set();
abstract final public void get();
}
class Test extends demo
{
public void set(int a)
{
this.a = a;
}
final public void get()
{
System.out.println("a = " + a);
}
public static void main(String[] args)
{
Test obj = new Test();
obj.set(20);
obj.get();
}
}
a = 10
a = 20
Compilation error
Question 10
Which of the following is FALSE about abstract classes in Java
If we derive an abstract class and do not implement all the abstract methods, then the derived class should also be marked as abstract using \'abstract\' keyword
Abstract classes can have constructors
A class can be made abstract without any abstract method
A class can inherit from multiple abstract classes.
There are 50 questions to complete.