wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA OOPS Test

Total questions: 88

Worksheet time: 3hrs 56mins

Name
Class
Date
1.

Default value of static integer variable of a class in java is

(a)  

2.

What is the default value of Boolean variable?

a)

TRUE

b)

FALSE

c)

NULL

d)

NOT DEFINED

3.

Which of the following statements are true for inheritance in java?

a)

"extend" keyword is used to extend a class in java.

b)

You can extend multiple classes in java.

c)

Private members of superclass are accessible to subclass.

d)

We can’t extend Final classes in java.

4.

Which of the following is not OOPS concept in Java?

a)

Inheritance

b)

Encapsulation

c)

Polymorphism

d)

Compilation

5.

Which concept of Java is achieved by combining methods and attribute into a class?

a)

Encapsulation

b)

Inheritance

c)

Polymorphism

d)

Abstraction

6.

Attributes of an object are also known as

a)

methods

b)

properties

c)

classes

d)

functions

7.

Properties of an OOPS are also known __________________ of JAVA Programming

a)

methods

b)

Characteristics

c)

classes

d)

functions

8.

Which of the following concepts of OOPs means exposing only necessary information and hiding the background details?

a)

Encapsulation

b)

Abstraction

c)

Data hiding

d)

Data binding

9.

As blueprint is a design for a house, a class is a design for a(n):

a)

object

b)

variable

c)

constant

d)

statement

10.
These have identitystate, and behavior.
a)
class
b)
object
c)
method
d)
void
11.

Which one is NOT the principle of OOP?

a)

Class

b)

Abstraction

c)

BlueJ

d)

Abstraction

e)

Encapsulation

12.
The wrapping up of data and functions into a single unit is called
a)
overloading
b)
class
c)
object
d)
encapsulation 
13.

In OOP the main importance is given to the

a)

methods

b)

procdures

c)

data

d)

objects

14.

Java uses both compiler and interpreter

a)

true

b)

false

15.

The system of using the existing class in another class is called

a)

encapsulation

b)

abstraction

c)

Inheritance

d)

abstraction

16.

Java was developed by

a)

James gosling

b)

John gosling

c)

James frank

d)

John frank

17.

Consider the given code. What would be the display on the screen?

a)

Class A

b)

Class B

c)

Class C

d)

Compile error

18.

What is the default value of a primitive int data type?

a)

-1

b)

null

c)

0

d)

garbage data

19.

Encapsulation is a process of wrapping of data and methods in a single unit called ------------------------------

a)

Variable

b)

Functions

c)

Class

d)

Box

20.

Which feature of OOPS derives the class from another class?

a)

Inheritance

b)

Data hiding

c)

Encapsulation

d)

Polymorphism

21.

How many types of polymorphism in the C++ programming language?

a)

Three types of polymorphism

b)

Two types of polymorphism

c)

Five types of polymorphism

d)

Four types of polymorphism

22.

Which of the following OOP concept binds the code and data together and keeps them secure from the outside world?

a)

Polymorphism

b)

Inheritance

c)

Abstraction

d)

Encapsulation

23.

Which member of the superclass is never accessible to the subclass?

a)

Public member

b)

Protected member

c)

Private member

d)

All of the mentioned

24.

How can the concept of encapsulation be achieved in the program?

a)

By using the Access specifiers

b)

By using the concept of Abstraction

c)

By using only private members

d)

By using the concept of Inheritance

25.

Which definition best defines the concept of abstraction?

a)

Hides the important data

b)

Hides the implementation and showing only the features

c)

Hiding the implementation

d)

Showing the important data

26.

Which of the following definition best describes the concept of polymorphism?

a)

It is the ability to process the many messages and data in one way

b)

It is the ability to process the undefined messages or data in at least one way

c)

It is the ability to process the message or data in more than one form

d)

It is the ability to process the message or data in only one form

27.

Which one of the following is not true?

a)

A class containing abstract methods is called an abstract class.

b)

Abstract methods should be implemented in the derived class.

c)

An abstract class cannot have non-abstract methods.

d)

A class must be qualified as ‘abstract’ class, if it contains one abstract method.

28.

What will be the output of the given program?

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

29.

What will be the output of the given program?

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

30.

Which of the following is true about inheritance in Java?


1) Private methods are final.

2) Protected members are accessible within a package and

inherited classes outside the package.

3) Protected methods are final.

4) We cannot override private methods.

a)

1, 2 and 4

b)

Only 1 and 2

c)

1, 2 and 3

d)

2, 3 and 4

31.

Predict the output of the following Java program


class Test {

int i;

}

class Main {

public static void main(String args[]) {

Test t = new Test();

System.out.println(t.i);

}

}

a)

garbage value

b)

0

c)

compiler error

d)

runtime error

32.

The output of the following Java program?

a)

Compilation error

b)

Inside First

Inside Second

c)

Inside First

Inside First

d)

Runtime error

33.

What is the output of the following JAVA program?

a)

dogood : dogoodgood

b)

dogood : gooddogood

c)

dogood : dogood

d)

dogood : gooddogood

34.

In Java, when we implement an interface method, it must be declared as:

a)

Private

b)

Protected

c)

Public

d)

Friend

35.

In Java, when we implement an interface method, it must be declared as:

a)

Private

b)

Protected

c)

Public

d)

Friend

36.

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

37.

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

38.

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

39.

what is the output of this question?

class Test1 {

static int x = 10;

public

static void main(String[] args)

{

Test1 t1 = new Test1();

Test1 t2 = new Test1();

t1.x = 20;

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

System.out.println(t2.x);

}

}

a)

10 10

b)

20 20

c)

10 20

d)

20 10

40.

What is the output of this question?

class Test1 {

static int i = 1;

public static void main(String[] args)

{

for (int i = 1; i < 10; i++) {

i = i + 2;

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

}

}

}

a)

3 6 9

b)

3 6 9 …. 27

c)

Error

d)

none

41.

What is the output of this question?

class Test1 {

static int i = 1;

public static void main(String[] args)

{

int i = 1;

for (Test1.i = 1; Test1.i < 10; Test1.i++) {

i = i + 2;

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

}

}

}

a)

1 3 9

b)

1 2 3 … 9

c)

3 5 7 9 11 13 15 17 19

d)

None

42.

What will be the output?

public class Test

{

public static void main(String args[])

{

int[] x=new int[3];

System.out.print("x[0] is" + x[0]);

}}

a)

The program has a compile error because the size of the array wasn't specified when declaring the array.

b)

The program has a runtime error because the array elements are not initialized.

c)

The program runs fine and displays x[0] is 0.

d)

The program has a runtime error because the array element x[0] is not defined

43.

An Array in Java is a collection of elements of ___ data type.

a)

Same

b)

Different

44.

The keyword "static" in Java is used with

a)

Method

b)

Block

c)

Variable

d)

All the Above

45.

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

46.

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

47.

Which of the following is not a correct statement?

a)

A class can have any number of static blocks

b)

Static method is accessed directly using class name

c)

Separate memory is allocated for each object for all static variables

d)

Static method is executed before main() method once a class is loaded

48.

Static variables belongs to an Object?

a)

Yes

b)

No

49.

What is the output of the following code?

public class Demo

{

static int x=10;

int y =15;

public Demo()

{

x++;

y++;

}


public static void main(String[] args)

{

Demo d1= new Demo();

Demo d2= new Demo();

Demo d3= new Demo();

System.out.println(d3.x + " , " +d3.y);

}


}

a)

13,15

b)

13,16

c)

13,18

d)

10, 18

50.

Which of the following is Mutable object

a)

String

b)

StringBuffer

51.

Which of these class is super class of every class in Java?

a)

String class

b)

Object class

c)

ArrayList class

d)

Abstract class

52.

Which of these keywords can be used to prevent inheritance of a class?

a)

super

b)

constant

c)

extends

d)

final

53.

Which of these class relies upon its subclasses for complete implementation of its methods?

a)

Object class

b)

abstract class

c)

ArrayList class

d)

None of the mentioned

54.

What will be the output of the following Java program?

a)

2

b)

0

c)

Compilation Error

d)

Runtime Error

55.

Which of these keywords are used to define an abstract class?

a)

Abstract

b)

abstract

c)

abstract class

d)

abst

56.

In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?

a)

Protected

b)

Private

c)

Public

d)

Static

57.

If super class and subclass have same variable name, which keyword should be used to use super class?

a)

this

b)

super

c)

upperclass

d)

classname

58.

What is the use of final keyword in Java?

a)

When a class is made final, a sublcass of it can not be created.

b)

When a method is final, it can not be overridden.

c)

When a variable is final, it can be assigned value only once.

d)

All of the above

59.

float myFloatNum = 5.99f;

System.out.println(myFloatNum);


What will be the output?

a)

5.99

b)

5.99f

c)

"5.99"

d)

"5.99"f

60.

Name the data type: 1.0

a)

double

b)

int

c)

char

d)

boolean

61.

Which of the following is the right way of defining char variable?

a)

char myGrade = 'B';

b)

char myGrade = "B";

c)

char myGrade 'B';

d)

char myGrade = "B"

62.

int sum1 = 100 + 50;

int sum2 = sum1 + 250;

int sum3 = sum2 + sum2;

System.out.println(sum3);


What will be the final output?

a)

950

b)

800

c)

sum2sum2

d)

sum1250

63.

int x = 10;

x = x + 5;

System.out.println(x);


What will be the output?

a)

15

b)

5

c)

55

d)

x5

64.

int x = 4;

System.out.println(x < 5 && x < 10);


What will be the output?

a)

false

b)

true

c)

4

d)

x < 5 && x < 10

65.

int x = 4.4;

int y = 5.5;

System.out.println(x == y);


What will be the output?

a)

4.4

b)

true

c)

false

d)

5.5

66.

What is the output of below code?


int x = 5;

System.out.println(x++);

System.out.println(x);

a)

5

5

b)

6

6

c)

5

6

d)

6

5

67.

Concatenation(+)operator is used for joining two strings

a)

true

b)

false

68.

Which of the following is not an OOPS concept in java ?

a)

Polymorphism

b)

Inheritance

c)

Compilation

d)

Encapsulation

69.

Which of these are selection statements in java

a)

Break

b)

Continue

c)

For ( )

d)

If ( )

70.

Which of these keywords is used to define interfaces in java

a)

intf

b)

Intf

c)

interface

d)

Interface

71.

Which one of the following is not an access modifier ?

a)

Protected

b)

Void

c)

Public

d)

Private

72.

When does method overloading is determined?

a)

At run time

b)

At compile time

c)

At coding time

d)

At execution time

73.

When overloading does not occur ?

a)

More than one method with same name but different method signature and different number or type of parameters

b)

More than one method with same name,same signature but different number of signature

c)

More than one method with same name,same signature,same number of parameters but different type

d)

More than one method with same , same number of parameters and type but different signature

74.

Method overriding is combination of inheritance and polymorphism ?

a)

True

b)

False

75.

Which of the below is invalid identifier with the main method

a)

Public

b)

Static

c)

Private

d)

Final

76.

What will be the output of the following Java program?

a)

0

b)

2

c)

4

d)

None of these

77.

Which of these can be used to fully abstract a class from its implementation?

a)

Objects

b)

Packages

c)

Interfaces

d)

None of the Mentioned

78.

What is the output of this program?

a)

a=10

b)

a=20

c)

Compilation Error

d)

No Error, but no output

79.

What type of variable can be defined in an interface?

a)

public static

b)

private final

c)

public final

d)

static final

80.

Which of the following is correct way of implementing an interface salary by class manager?

a)

class manager extends salary {}

b)

class manager implements salary {}

c)

class manager imports salary {}

d)

None of the mentioned.

81.

Abstract class can have constructors and static methods?

a)

TRUE

b)

FALSE

c)

Abstract class can have constructors but can not have static methods.

d)

Abstract class can not have constructors but can have static methods.

82.

Which of these is not a correct statement?

a)

Every class containing abstract method must be declared abstract

b)

Abstract class defines only the structure of the class not its implementation

c)

Abstract class can be initiated by new operator

d)

Abstract class can be inherited

83.

A class that is inherited is called a ______ .

a)

superclass

b)

Subclass

c)

subsetclass

d)

Relativeclass

84.

Class dog implements the animal interface.

Which IS a valid declaration?

a)

Dog d = new Animal();

b)

Animal d = new Dog();

c)

Animal d = new Animal();

85.
Which of these cannot be passed down through inheritance?
a)
Public variables
b)
Private variables
c)
Methods
d)
Data
86.

When overloading a method, the method header ________ .

a)

Must exactly match the header of the method you are overloading.

b)

Must have the same name, but differ in order, number, or type of parameters.

c)

Can differ in name, but must have the same number and order of parameters.

d)

Can be completely different from the method you are overloading, but must have @Override.

87.

Which of the following statements is invalid?

a)

Tutor jimmy = new CSTutor();

b)

CSTutor sally = new JavaTutor();

c)

Tutor suzie = new JavaTutor();

d)

Tutor johnny = new Tutor();

88.

Abstract class can have

a)

Abstract methods

b)

Methods with code implementation

c)

Used to create objects

d)

Used to create subclasses