Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

UNIT1

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which is not a feature of OOP?

a)

Encapsulation

b)

Inheritance

c)

Compilation

d)

Polymorphism

2.

Java supports multiple inheritance using:

a)

class

b)

abstract class

c)

interface

d)

object

3.

Keyword to inherit class

a)

this

b)

extends

c)

super

d)

implements

4.

int x = 2;

x *= 3 + 4;

System.out.println(x);

a)

14

b)

10

c)

6

d)

Compilation error

5.

System.out.println(10 + 20 + "Java" + 10 + 20);

a)

30Java1020

b)

Java102030

c)

Java30

d)

Compilation error

6.

Which of the following correctly creates an object in Java?

a)

MyClass obj = MyClass();

b)

obj = new MyClass;

c)

MyClass obj = new MyClass();

d)

class MyClass = new Object();

7.

Which statement is true about abstract classes?

a)

They can be instantiated

b)

They can't have any method body

c)

They can have both abstract and non-abstract methods

d)

They are always final

8.

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 {}

a)

No error

b)

Class B must implement display()

c)

Abstract class must be final

d)

Abstract class can't be inherited**

9.

What happens when you try to instantiate an abstract class?

a)

It compiles and runs

b)

Compile-time error

c)

Object is created

d)

JVM throws error at runtime

10.

Fill in the blank to refer to current class’s variable:

public void setName(String name) {

_____ .name = name;

}

a)

this

b)

super

c)

final

d)

abstract

11.

A __________ method in Java belongs to the class rather than an object.

a)

virtual

b)

static

c)

private

d)

abstract

12.

Which class defines the finalize() method by default?

a)

Runtime

b)

Thread

c)

Object

d)

ClassLoader

13.

__________ means binding data and methods into a single unit.

a)

Abstraction

b)

Encapsulation

c)

Polymorphism

d)

Data Hiding

14.

What is the purpose of the 'super' keyword?

a)

Refers to current class

b)

Used for dynamic memory allocation

c)

Refers to static members

d)

Refers to parent class members

15.

Accessing private variable from another class:

s.marks = 90; // marks is private

a)

No error

b)

Compile-time error

c)

Runtime error

d)

Logical error

16.

Which is a valid overloaded method?

void print(int a) {}

void print(String s) {}

a)

No, methods must differ by name

b)

Yes, parameter types differ

c)

No, return type must differ

d)

No, static required

17.

What is the purpose of the finalize() method in Java?

a)

To finalize variable values before method ends

b)

To clean up resources before garbage collection

c)

To perform cleanup before object destruction

d)

To finalize static methods

18.

Which of the following is a correct override of the finalize() method?

a)

public void finalize() throws Throwable

b)

private void finalize()

c)

public void finalize()

d)

public int finalize()

19.

Which is a valid overriding method?

class A { void show() {} }

class B extends A { void show() {} }

a)

Invalid - must be static

b)

Invalid - method name must differ

c)

Valid - same method signature

d)

Invalid - must be final

20.

class A {

void show() {}

}

class B extends A {

int show() { return 1; }

}

a)

No error

b)

Return type mismatch in overriding

c)

Constructor misuse

d)

Static method error