wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

OOP - Java Classes

Total questions: 15

Worksheet time: 12mins

Name
Class
Date
1.

Which one of the following is a valid statement?

a)

char[] c = new char();

b)

char[] c = new char[5];

c)

char[] c = new char(4);

d)

char[] c = new char[];

2.

Which is the correct way of knowing Array Size in Java?

a)

int[] ary;

ary.length()

b)

int[] ary;

ary.length

c)

int[] ary;

ary->length()

d)

int[] ary;

ary->length

3.

A ___________ is a pre-defined set of steps that complete a specific task, optionally based on parameter values, and optionally returning some result.

a)

array

b)

function

c)

method

d)

module

e)

class

4.

Predict the output of the following program.


class A{

int a=40;//non static

public static void main(String args[]){

System.out.println(a);

}

}

a)

Compilation Error

b)

40

c)

0

d)

None of the above

5.

what is the output of this question?

class Test1 {

public

static void main(String[] args)

{

int x = 20;

System.out.println(x);

}

static

{

int x = 10;

System.out.print(x + " ");

}

}

a)

10 20

b)

20 10

c)

10 10

d)

20 20

6.

Which of the following variable is declared as static?

a)

Home address of a particular Student

b)

Account number of a Customer

c)

Company name of all Employees in an Organization

d)

Name of a Employee

7.

What is the output of the following code?

public class Demo

{

public void show(int a)

{

System.out.println(a);

}

public static void main(String[] args)

{

show(20);

}

}

a)

20

b)

No Output Displayed

c)

a constant is passed as argument

d)

Compile Time Error

8.

Output of following Java Program?

a)

10

b)

20

c)

Compilation Error

d)

Run Time Error

9.

Output of following Java Program?

a)

12

b)

321

c)

123

d)

23

10.

What is subclass in java?

a)

A subclass is a class that extends another class

b)

A subclass is a class declared inside a class

c)

Both above.

d)

None of the above.

11.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

12.

Which of this keyword must be used to inherit a class?

a)

super

b)

this

c)

extent

d)

extends

13.

Which of these is correct way of inheriting class A by class B?

a)

class B + class A {}

b)

class B inherits class A {}

c)

class B extends A {}

d)

class B extends class A {}

14.

A package is a collection of

a)

classes

b)

interfaces

c)

editing tools

d)

classes and interfaces

15.

which package is imported implicitly?

a)

java.applet

b)

java.util

c)

java.lang

d)

java.io