wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Accenture_Java_OOPs

Total questions: 50

Worksheet time: 3hrs 36mins

Name
Class
Date
1.
a)

peep

b)

bark

c)

meow

d)

Compilation fails

e)

An exception is thrown at runtime.

2.
a)

Cat is-a Animal

b)

Cat is-a Jumper

c)

Dog is-a Animal

d)

Beagle has-a Tail

e)

Beagle has-a Jumper

3.
a)

Compilation fails.

b)

An exception is thrown at runtime.

c)

The attribute id in the Item object remains unchanged.

d)

The attribute id in the Item object is modified to the new value.

e)

A new Item object is created with the preferred value in the id attribute.

4.

Which Man class properly represents the relationship "Man has a best friend who is a Dog"?

a)

class Man extends Dog { }

b)

class Man implements Dog { }

c)

class Man { private BestFriend dog; }

d)

class Man { private Dog bestFriend; }

e)

class Man { private Dog<bestFriend>; }

5.

What will be the result of attempting to compile and run the following code?

a)

A) null

b)

B) John

c)

C) Compilation error

d)

D) Runtime error

6.

What does the following code demonstrate?

a)

A) Inheritance

b)

B) Polymorphism

c)

C) Encapsulation

d)

D) Abstraction

7.

What will be the output of the following Java code?

a)

0 0

b)

5 6

c)

6 5

d)

5 5

8.

What is the output of the following Java code?

a)

5

b)

0

c)

Garbage Value

d)

-1

9.

What is the output of the following Java code?

a)

8

b)

10

c)

0

d)

Compilation Error

10.

What will be the output of the following Java code?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

11.

What will be the output of the following Java program?


a)

0

b)

1

c)

2

d)

Compilation Error

12.

What will be the output of the following Java program?


a)

0

b)

2

c)

4

d)

None of the mentioned

13.
a)

1,3 and 4

b)

1,2 and 4

c)

2,3 and 4

d)

1,2,3 and 4

14.

a)

1 and 2 only

b)

2,3 and 5

c)

3,4 and 5

d)

2 and 4

15.

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

16.

What type of variable can be defined in an interface?

a)

public static

b)

private final

c)

public final

d)

static final

17.

What does an interface contain?

a)

Method definition

b)

Method declaration

c)

Method declaration and definition

d)

Method name

18.

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.

19.

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.

20.

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

21.

The following Syntax is used for?


class Subclass-name extends Superclass-name

{

//methods and fields

}

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

None of the above

22.

A class that is inherited is called a ______ .

a)

superclass

b)

Subclass

c)

subsetclass

d)

Relativeclass

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

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.

25.

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();

26.

Abstract class can have

a)

Abstract methods

b)

Methods with code implementation

c)

Used to create objects

d)

Used to create subclasses

27.

What is an abstract method?

a)

An abstract method is any method in an abstract class.

b)

An abstract method is a method which cannot be inherited.

c)

An abstract method is one without a body that is declared with the reserved word abstract.

d)

n abstract method is a method in the child class that overrids a parent method.

28.

A class can implement more than one interface?

a)

True

b)

False

29.

A class can extend an interface?

a)

True

b)

False

30.

An interface can extend an interface?

a)

True

b)

False

31.

All members of an interface are public by default?

a)

True

b)

False

32.

Predict the output:

a)

20

b)

10

c)

Error in Object creation

d)

None of the above

33.

super keyword in Java is used for ?

a)

to refer to immediate child class of a class.

b)

to refer to current class object.

c)

to refer to immediate parent class of a class.

d)

to refer to static member of parent class.

34.

Which is true ?

a)

"X extends Y" is correct if X and Y are either both classes or both interface.

b)

"X extends Y" is correct if and only if X is a interface and Y is a class.

c)

"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.

d)

"X extends Y" is correct if and only if X is a class and Y is an interface.

35.

If a class inheriting an abstract class does not define all of its function then it will be known as?

a)

abstract

b)

A simple class

c)

Static class

d)

None of the mentioned

36.

Can an abstract class define both abstract methods and non-abstract methods?

a)

No—it must have all one or the other.

b)

No—it must have all abstract methods.

c)

Yes—but the child classes do not inherit the abstract methods.

d)

Yes—the child classes inherit both.

37.
Inheritance is used when the relationship between two classes is a(n) _______ relationship.
a)
"HAS-A"
b)
"PART-OF-A"
c)
"IS-A"
d)
inverse
38.

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

a)

String class

b)

Object class

c)

ArrayList class

d)

Abstract class

39.

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

a)

super

b)

constant

c)

extends

d)

final

40.

Which inheritance in java programming is not supported

a)

Multiple inheritance using classes

b)

Multiple inheritance using interfaces

c)

Multilevel inheritance

d)

Single inheritance

41.

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.

42.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

43.

Predict the output of following program

a)

Base

b)

Derived

c)

Compiler Error

d)

Runtime Error

44.

In Java, if a subclass defines a static method with the same signature as a static method in the superclass, what is this an example of?

a)

Method overriding

b)

Method overloading

c)

Method hiding

d)

Illegal code

45.

Which of the following is/are false about inheritance in Java?

I. A subclass inherits all the methods and variables of the superclass.

II. A subclass can override the methods of its superclass

III. A subclass has access to the private instance variables of the superclass.

a)

I only

b)

II only

c)

III only

d)

I and II only

e)

I and III only

46.
What is the output of running the class c?
a)
AB
b)
BA
c)
AA
d)
BB
47.

Q14. What will the following program output?

(a)  

48.

Q1. (Multiple Choice)
Which type of polymorphism is achieved through method overloading?

a)

Runtime polymorphism

b)

Compile-time polymorphism

c)

Dynamic polymorphism

d)

None of the above

49.

Q4. (Code Analysis)
What is the output of this code?

(a)  

50.

As a Vehicle user, we know how to use it but its internal working are not known. In OOPs Concept, this principle is known as

a)

Encapsulation

b)

Inheritance

c)

Abstraction

d)

Polymorphism