wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java core OOP

Total questions: 57

Worksheet time: 29mins

Name
Class
Date
1.

In OOP, Polymorphism appears

a)

When one object acquires all the properties and behaviours of parent object

b)

When one task is performed by different ways

c)

When hiding internal details and showing functionality

d)

When biding for wrapping code and data together into a single unit

2.

A class in java can contain

a)

Fields

b)

Methods

c)

Constructors

d)

Nested class and interfce

e)

All are true

3.

The ways to create an object in java are

a)

By new keyword

b)

By newinstance() method

c)

by clone() method

d)

All of the answers

4.

Rules for creating Java constructor

a)

Constructor name must be same as its class name

b)

Constructor must have no explicit return

c)

Constructor must have no parameter

d)

All of the answers

e)

Only A and B are TRUE

5.
  1. Inheritance in Java

a)

Represents the IS-A relationship

b)

Represents the has a relationship, also known as parent child relationship

c)

Is a mechanism in which you can not create new classes that are built upon exisiting classes

6.
  1. Method Overloading in Java is known as

a)

If a class has multiple methods having the same name and same params

b)

if a class has multiple methods having different in params

c)

If a class has multiple methods having the same name but different in params

7.

The ways to overload the method in Java

a)

By changing the number of arguments

b)

By changing the data type of arguments

c)

All of the above

d)

None of the above

8.
  1. Method Overloading in Java known as

a)

If a class has multiple methods having same name but different in params

b)

If subclass (child class) has the same method as declared in the parent class

c)

Represents HAS -A relationship

d)

Subclass provides the specific implementation of the method that has not been provided by one of its parent class

9.
  1. 9. Rules for Java Method Overriding

a)

Method must have same name as in the parent class

b)

Method must have been parameter as in the parent class

c)

Method must have same parameter as in parent class

d)

All of the above

10.
  1. 10. Can we override static method

a)

Yes

b)

No

c)

Sometime yes, sometime no

11.
  1. 11. The public access modifier is accessible

a)

within package and outside the package but through inheritance only

b)

within package only

c)

outside the package but through inheritance only

d)

everywhere

12.
  1. 12. The private access modifier is accessible

a)

within package only

b)

within class only

c)

outside the package but through inheritance only

d)

everywhere

13.
  1. Do you agree with the following "Constructors in the class do not have the return type"

a)

Right

b)

Wrong

14.

Do you agree with the following: "Object class in a superclass of all of the classes in Java"

a)

Right

b)

Wrong

15.
  1. An abstract class can be declared with final modifier

a)

True

b)

False

16.
  1. 16. If a class does not want to implement all the methods of interface, what is this class?

a)

Interface

b)

Normal class

c)

Abstract class

d)

None of the above

17.

Which of the following is true?

a)

An abstract method can not override an another abstract method

b)

A specific method can not override an another abstract method

c)

An abstract method can not be declared with the keyword throws

d)

No sentences above are ture

18.
  1. 18. What is the result of attempting to compile and run the program
    class M{
    main(){
    string s =null
    print(s)}

a)

Print nothing

b)

Prints: null

c)

Compile error

d)

aaa

19.

What is the result of attempting to compile and run the program?

a)

Error at line 1

b)

Error at line 2

c)

Error at line 3

d)

Error at line 4

e)

No error

20.

Which of the following modifier can be applied to a constructor

a)

private

b)

abstract

c)

final

d)

none of them above

21.

Which of the following modifiers can not be

a)

abstract

b)

final

c)

private

d)

static

22.

Which if the following modifiers can not be applied to a method

a)

abstract

b)

private

c)

static

d)

None of the above

23.

Which of the following modifiers can not be applied to a constructor?

a)

protected

b)

public

c)

private

d)

static

24.

24 which of the following modifiers can be used with the abstract modifier in a method declaration

a)

final

b)

private

c)

protected

d)

static

25.

25 . Which of the following modifiers can be used with the abstract modifier in a method declaration?

a)

Static

b)

Final

c)

Private

d)

Public

26.

26 . Compile -time errors are generated at which line?

a)

1

b)

2

c)

3

d)

4

27.
  1. Compile time errors are not generated at which line

a)

1

b)

2

c)

3

d)

4

28.

28 WHich of the following are modifiers that can be applied to a feild declaration with an interface?

a)

Abstract

b)

Const

c)

Final

d)

Private

29.

Which of the following are modifiers that can be applied to a field declaration within an interface

a)

Abstract

b)

static

c)

private

d)

protected

30.
  1. 30. Which of the following are modifiers that can be applied to field declaration within an interface

a)

public

b)

private

c)

protected

d)

No modifiers

31.

Which field declaration result in compile time error?

a)

1

b)

2

c)

3

d)

None of the above

32.

What is the result of attempting to compile and run the program?
Note: Upcasting will make object see only parent class.

a)

Prints Y.s1 X.s2 Y.s1 X.s2

b)

Prints: Y.s1 X.s2 X.s1 X.s2

c)

Prints X.s1 X.s2 Y.s1 Y.s2

d)

Prints: X.s1 X.s2 X.s1 X.s2

33.

What is result?
Note:
- Loại Quyết định bởi Kết quả khi upcasting
-
Field (thuộc tính) Kiểu biến (compile-time)
=> x.field dùng field của X
-
Method (hàm) Kiểu object thật (run-time)
=> x.method() gọi method override của Y

a)

AAA

b)

ABC

c)

CBA

d)

CCC

34.
  1. 34. Which of the following modifiers can be apllied to a class that is not a nested class?

a)

private

b)

protected

c)

abstract

d)

static

35.
a)

Private

b)

protected

c)

static

d)

final

36.

36

a)

private

b)

protected

c)

default

d)

static

37.
a)

A

b)

B

c)

C

d)

D

38.
a)

Prints: R.printS1 R.printS2

b)

Prints: R.printS1 S.printS2

c)

Prints: S.printS1 R.printS2

d)

Prints: S.printS1 S.printS2

39.
a)

Print DD

b)

Print DE

c)

Print ED

d)

Print EE

40.
  1. 40.
    Note
    Hàm khởi tạo in Java: Không được kế thừa
    Nếu lớp cha không có constructor mặc định thì lớp con phải tự định nghĩa constructor và gọi super(...) đến một constructor của lớp cha.
    Constructor của lớp cha luôn chạy trước constructor của lớp con.

a)

A

b)

B

c)

C

d)

D

41.

Java final keyword can be used in many context

a)

Variable

b)

Method

c)

Class

d)

A, B only

e)

A, B and C

42.

Which of the following opinion is TRUE?

a)

Final method cannot be inherited and you cannot override it

b)

Final method is inherited and you can override it

c)

Final method is inherited and you cannot override it

d)

None of the above

43.

Can we declare a constructor final

a)

No, because constructor is never inherited

b)

Yes, because constructor is never inherited

c)

Sometimes yes sometimes No

44.

In Java, String objects are immutable. Immutabke simply means that

a)

String object unmodifiable or unchangeable

b)

Once String object is created its data or state can't be changed but a new string object is created

c)

All of the above

d)

None of the above

45.

Note
✔ Bạn được khai báo biến local mà không gán giá trị

✘ Bạn không được sử dụng biến local nếu chưa gán giá trị

a)

Compile time error at line 1

b)

Compile time error at line 2

c)

Compile time error at line 3

d)

Compile time error at line 4

46.

Note:
Call x without calling object

a)

Prints 0,0

b)

Compile error line 1

c)

Compile error line 2

d)

Compile error line 3

47.
a)

Prints main, B.m1

b)

Prints main, B.m1

c)

Compile err

d)

Noen of the above

48.

W sẽ có tổng cộng 4 method m1 => Overload not override

a)

Print XXX

b)

Print XYZ

c)

Print WWW

d)

Print XYZW

49.
a)

Print AAA

b)

Print ABC

c)

Print CCC

d)

None of the above

50.
  • - Trong overload, uư tiên goi con truoc

a)

Print Object

b)

Print String

c)

Compile Error

d)

Run time error

51.

A

a)

ABACA

b)

ABABAB

c)

ABABCAB

d)

ABABCABC

52.

Trim(); cắt khoảng trắng 2 đầu, ko ở giữa
Concat(string S):

a)

ABC

b)

A B C

c)

ABCD

d)

ABDC

53.

Result?

a)

True,fasle

b)

false,true

c)

True, true

d)

false, false

54.

Result?

a)

false, false

b)

T, T

c)

T,F

d)

F,T

55.

Result?

a)

True False

b)

False, True

c)

True, True

d)

False False

56.
a)

True False

b)

True True

c)

False, False

d)

False True

57.
a)

0001

b)

1110

c)

1101

d)

0111