WorksheetsUNIT1
Total questions: 20
Worksheet time: 10mins
Which is not a feature of OOP?
Encapsulation
Inheritance
Compilation
Polymorphism
Java supports multiple inheritance using:
class
abstract class
interface
object
Keyword to inherit class
this
extends
super
implements
int x = 2;
x *= 3 + 4;
System.out.println(x);
14
10
6
Compilation error
System.out.println(10 + 20 + "Java" + 10 + 20);
30Java1020
Java102030
Java30
Compilation error
Which of the following correctly creates an object in Java?
MyClass obj = MyClass();
obj = new MyClass;
MyClass obj = new MyClass();
class MyClass = new Object();
Which statement is true about abstract classes?
They can be instantiated
They can't have any method body
They can have both abstract and non-abstract methods
They are always final
Which of the following is valid usage of abstract class that does not cause error?
abstract class A {
abstract void display();
}
class B extends A {}
No error
Class B must implement display()
Abstract class must be final
Abstract class can't be inherited**
What happens when you try to instantiate an abstract class?
It compiles and runs
Compile-time error
Object is created
JVM throws error at runtime
Fill in the blank to refer to current class’s variable:
public void setName(String name) {
_____ .name = name;
}
this
super
final
abstract
A __________ method in Java belongs to the class rather than an object.
virtual
static
private
abstract
Which class defines the finalize() method by default?
Runtime
Thread
Object
ClassLoader
__________ means binding data and methods into a single unit.
Abstraction
Encapsulation
Polymorphism
Data Hiding
What is the purpose of the 'super' keyword?
Refers to current class
Used for dynamic memory allocation
Refers to static members
Refers to parent class members
Accessing private variable from another class:
s.marks = 90; // marks is private
No error
Compile-time error
Runtime error
Logical error
Which is a valid overloaded method?
void print(int a) {}
void print(String s) {}
No, methods must differ by name
Yes, parameter types differ
No, return type must differ
No, static required
What is the purpose of the finalize() method in Java?
To finalize variable values before method ends
To clean up resources before garbage collection
To perform cleanup before object destruction
To finalize static methods
Which of the following is a correct override of the finalize() method?
public void finalize() throws Throwable
private void finalize()
public void finalize()
public int finalize()
Which is a valid overriding method?
class A { void show() {} }
class B extends A { void show() {} }
Invalid - must be static
Invalid - method name must differ
Valid - same method signature
Invalid - must be final
class A {
void show() {}
}
class B extends A {
int show() { return 1; }
}
No error
Return type mismatch in overriding
Constructor misuse
Static method error
