wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Basics of OOP with JAVA

Total questions: 25

Worksheet time: 20mins

Name
Class
Date
1.

When is the object created with new keyword?

a)

At compile time

b)

At run time

c)

Depends on the code

d)

At execution time

2.

Java is a platform independent programming language

a)

True

b)

False

3.

What is a correct difference between print() and println()?

a)

print() prints the output and move to new line, println() prints the output and stays on same line

b)

print() prints the output and stays on same line, println() prints the output and move to new line

c)

None of the given

d)

Both of the given

4.

What is the problem with this code?

Line 1: String myName = "Luna";

Line 2: System.out.println ("My name is " + myname);

a)

Line 2: should be System.out.println ("My name is myName");

b)

Line 2: should be System.out.println ("My name is "+ myName);

c)

Line 2: should be System.out.display("My name is " + myname);

d)

There is no problem with the code

5.

Which of these cannot be used for a variable name in java ?

a)

Identifier & keyword

b)

Identifier

c)

Keyword

d)

None of the mentioned

6.

Is the process by which one object can acquire the properties of another object.

a)

Polymorphism

b)

Inheritance

c)

Encapsulation

d)

Object-Oriented Programming

7.

A ___________ file is created after successful compilation of a Java program.

a)

Object file

b)

Array file

c)

Class file

d)

String file

8.

Which of the following is a part of Java Development Kit?

a)

Java runtime environment

b)

Java Development kit

c)

Java Virtual Machine

d)

All of them

9.

A Java file with extension .class contains

a)

Java source code

b)

HTML Tags

c)

Java Bytecodes

d)

A program file written in java programming language

10.

Which of the following is not a primitive data type of JAVA?

a)

int

b)

char

c)

String

d)

float

11.

Scanner inp= new Scanner(System.in);

What is System.in in this declaration?

a)

Any file storing data

b)

Reference to standard input device, that is, keyboard

c)

Reference to a scanner as an input device

d)

It is a mouse as an input device

12.

Polymorphism related to :

a)

PPO

b)

Class

c)

OPP

d)

OOP

13.

Which from the following is a feature that allows us to perform a single action in different ways.

a)

Abstraction

b)

Polymorphism

c)

Encapsulation

d)

Inheritance

14.

The process by which objects of one class acquire the properties of objects of another class is known as

a)

Polymorphism

b)

Inheritance

c)

Data Hiding

d)

Association

15.

Hiding complexity can also be termed as

a)

Inheritance

b)

Overloading

c)

Data hiding

d)

Abstraction

16.
How many objects can be made from a class? 
a)
None, you make classes from objects
b)
one
c)
As many as you want
d)
All of the above
17.

Father of Java

a)

Dennis Ritchie

b)

James Gosling

c)

Bill Joy

d)

Bjarne Stroustrup

18.

What is the file extension for Java Source Code?

a)

.java

b)

.class

c)

.exe

d)

.obj

19.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

System.out.println("c = " + c);

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

20.

What will be the output of the program?

class Test

{

public static void main(String [] args)

{

int x=20;

String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";

System.out.println(sup);

}

}

a)

small

b)

tiny

c)

huge

d)

Compilation fails

21.

What is the value of y after evaluating the expression given below?

y += ++y + y–– + ––y; when int y=8

(a)  

22.

How many times is "HI!" printed?

a)

15

b)

12

c)

10

d)

8

e)

Infinite Loop

23.

A SWITCH fall through occurs in Java only in the absence of ___.

a)

Keyword "case"

b)

Keyword "break"

c)

Keyword "default"

d)

None of these

24.

What is the output of the below Java program with a SWITCH statement?


int points=6;

switch(points)

{

case 6: ;

case 7: System.out.print("PASS");

case 8: ;

case 9: System.out.print(" Excellent");

case 10: System.out.print(" Outstanding"); break;

default: System.out.print("FAIL");

}

a)

PASS Excellent Outstanding

b)

Excellent

c)

Outstanding

d)

FAIL

25.

Predict the output?


class jump_statments

{

public static void main(String args[])

{

int x = 2;

int y = 0;

for ( ; y < 10; ++y)

{

if (y % x == 0)

continue;

else if (y == 8)

break;

else

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

} } }

a)

1 3 5 7

b)

2 4 6 8

c)

1 3 5 7 9

d)

1 2 3 4 5 6 7 8 9