Font size
WorksheetsJava core OOP
Total questions: 57
Worksheet time: 29mins
In OOP, Polymorphism appears
When one object acquires all the properties and behaviours of parent object
When one task is performed by different ways
When hiding internal details and showing functionality
When biding for wrapping code and data together into a single unit
A class in java can contain
Fields
Methods
Constructors
Nested class and interfce
All are true
The ways to create an object in java are
By new keyword
By newinstance() method
by clone() method
All of the answers
Rules for creating Java constructor
Constructor name must be same as its class name
Constructor must have no explicit return
Constructor must have no parameter
All of the answers
Only A and B are TRUE
Inheritance in Java
Represents the IS-A relationship
Represents the has a relationship, also known as parent child relationship
Is a mechanism in which you can not create new classes that are built upon exisiting classes
Method Overloading in Java is known as
If a class has multiple methods having the same name and same params
if a class has multiple methods having different in params
If a class has multiple methods having the same name but different in params
The ways to overload the method in Java
By changing the number of arguments
By changing the data type of arguments
All of the above
None of the above
Method Overloading in Java known as
If a class has multiple methods having same name but different in params
If subclass (child class) has the same method as declared in the parent class
Represents HAS -A relationship
Subclass provides the specific implementation of the method that has not been provided by one of its parent class
9. Rules for Java Method Overriding
Method must have same name as in the parent class
Method must have been parameter as in the parent class
Method must have same parameter as in parent class
All of the above
10. Can we override static method
Yes
No
Sometime yes, sometime no
11. The public access modifier is accessible
within package and outside the package but through inheritance only
within package only
outside the package but through inheritance only
everywhere
12. The private access modifier is accessible
within package only
within class only
outside the package but through inheritance only
everywhere
Do you agree with the following "Constructors in the class do not have the return type"
Right
Wrong
Do you agree with the following: "Object class in a superclass of all of the classes in Java"
Right
Wrong
An abstract class can be declared with final modifier
True
False
16. If a class does not want to implement all the methods of interface, what is this class?
Interface
Normal class
Abstract class
None of the above
Which of the following is true?
An abstract method can not override an another abstract method
A specific method can not override an another abstract method
An abstract method can not be declared with the keyword throws
No sentences above are ture
18. What is the result of attempting to compile and run the program
class M{
main(){
string s =null
print(s)}
Print nothing
Prints: null
Compile error
aaa
What is the result of attempting to compile and run the program?
Error at line 1
Error at line 2
Error at line 3
Error at line 4
No error
Which of the following modifier can be applied to a constructor
private
abstract
final
none of them above
Which of the following modifiers can not be
abstract
final
private
static
Which if the following modifiers can not be applied to a method
abstract
private
static
None of the above
Which of the following modifiers can not be applied to a constructor?
protected
public
private
static
24 which of the following modifiers can be used with the abstract modifier in a method declaration
final
private
protected
static
25 . Which of the following modifiers can be used with the abstract modifier in a method declaration?
Static
Final
Private
Public
26 . Compile -time errors are generated at which line?
1
2
3
4
Compile time errors are not generated at which line
1
2
3
4
28 WHich of the following are modifiers that can be applied to a feild declaration with an interface?
Abstract
Const
Final
Private
Which of the following are modifiers that can be applied to a field declaration within an interface
Abstract
static
private
protected
30. Which of the following are modifiers that can be applied to field declaration within an interface
public
private
protected
No modifiers
Which field declaration result in compile time error?
1
2
3
None of the above
What is the result of attempting to compile and run the program?
Note: Upcasting will make object see only parent class.
Prints Y.s1 X.s2 Y.s1 X.s2
Prints: Y.s1 X.s2 X.s1 X.s2
Prints X.s1 X.s2 Y.s1 Y.s2
Prints: X.s1 X.s2 X.s1 X.s2
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
AAA
ABC
CBA
CCC
34. Which of the following modifiers can be apllied to a class that is not a nested class?
private
protected
abstract
static
Private
protected
static
final
36
private
protected
default
static
A
B
C
D
Prints: R.printS1 R.printS2
Prints: R.printS1 S.printS2
Prints: S.printS1 R.printS2
Prints: S.printS1 S.printS2
Print DD
Print DE
Print ED
Print EE
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
B
C
D
Java final keyword can be used in many context
Variable
Method
Class
A, B only
A, B and C
Which of the following opinion is TRUE?
Final method cannot be inherited and you cannot override it
Final method is inherited and you can override it
Final method is inherited and you cannot override it
None of the above
Can we declare a constructor final
No, because constructor is never inherited
Yes, because constructor is never inherited
Sometimes yes sometimes No
In Java, String objects are immutable. Immutabke simply means that
String object unmodifiable or unchangeable
Once String object is created its data or state can't be changed but a new string object is created
All of the above
None of the above
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ị
Compile time error at line 1
Compile time error at line 2
Compile time error at line 3
Compile time error at line 4
Note:
Call x without calling object
Prints 0,0
Compile error line 1
Compile error line 2
Compile error line 3
Prints main, B.m1
Prints main, B.m1
Compile err
Noen of the above
W sẽ có tổng cộng 4 method m1 => Overload not override
Print XXX
Print XYZ
Print WWW
Print XYZW
Print AAA
Print ABC
Print CCC
None of the above
- Trong overload, uư tiên goi con truoc
Print Object
Print String
Compile Error
Run time error
A
ABACA
ABABAB
ABABCAB
ABABCABC
Trim(); cắt khoảng trắng 2 đầu, ko ở giữa
Concat(string S):
ABC
A B C
ABCD
ABDC
Result?
True,fasle
false,true
True, true
false, false
Result?
false, false
T, T
T,F
F,T
Result?
True False
False, True
True, True
False False
True False
True True
False, False
False True
0001
1110
1101
0111
