0% found this document useful (0 votes)
79 views7 pages

Bai Tap Trac Nghiem Oop

The document contains a multiple choice quiz on object-oriented programming concepts. There are 20 questions in the first part testing concepts like inheritance, polymorphism, and abstraction. The second part contains 7 more questions on classes, constructors, and static methods. The third part has 10 additional questions to further test understanding of OOP principles like encapsulation, inheritance, and polymorphism.

Uploaded by

water5ngan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views7 pages

Bai Tap Trac Nghiem Oop

The document contains a multiple choice quiz on object-oriented programming concepts. There are 20 questions in the first part testing concepts like inheritance, polymorphism, and abstraction. The second part contains 7 more questions on classes, constructors, and static methods. The third part has 10 additional questions to further test understanding of OOP principles like encapsulation, inheritance, and polymorphism.

Uploaded by

water5ngan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

lOMoARcPSD|34127520

Bai Tap Trac Nghiem OOP

Lập trình hướng đối tượng (Đại học Tôn Đức Thắng)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Huy Lê ([email protected])
lOMoARcPSD|34127520

Bài tập OOP – Trắc nghiệm


Chọn đáp án (A, B, C, D) đúng nhất, giải thích ngắn gọn lý do tại sao bạn chọn đáp án
đó.
Câu 1 HAS-A relationships are based on inheritance, rather than usage
A. True
B. False
Câu 2 Array or collection of superclass references can be used to access a mixture of
superclass and subclass objects.
A. True
B. False
Câu 3 Aggregation is a special form of association.
A. True
B. False
Câu 4 An interface cannot have an inner class
A. True
B. False
Câu 5 Method overloading is done during _______.
A. Runtime
B. Dynamic binding
C. Program compilation
D. Late binding
Câu 6 Ad hoc polymorphism is ____________
A. Method Overloading
B. Method Overriding
C. Subclassing polymorphism
D. Dynamic binding
Câu 7 The inheriting class cannot override the definition of existing methods by providing
its own implementation.
A. True
B. False
Câu 8 The two most common reasons to use inheritance are( choose 2)
A. To promote code reuse
B. To use abstraction
C. To use interface
D. To use polymorphism

Downloaded by Huy Lê ([email protected])


lOMoARcPSD|34127520

Câu 9 The benefits of the Object Orientation are: (choose two)


A.Inheritance
B.Flexibility
C.Maintainability
D.Polymorphism
Câu 10 Below is the sample code : 1 class Hotel { 2 public int bookings; 3 public void
book() { 4 bookings++; 5 } 6 } 7 public class SuperHotel extends Hotel { 8 public
void book() { 9 bookings--; 10 } 11 public void book(int size) { 12 book(); 13
super.book(); 14 bookings += size; 15 } 16 public static void main(String args[]) { 17
Hotel hotel = new Hotel(); 18 hotel.book(2); 19 System.out.print(hotel.bookings); 20 }}
How can we correct the above code? (choose all that apply)

A.By adding argument "int size" to the method book at line number 3.
B.By removing argument '2' at line number 18.
C.By creating object of "SuperHotel" subclass at line 17 & calling book(2) from it at line 18
D.No correction needed.
Câu 11 At run-time, a Java program is nothing more than objects ‘talking’ to
___________.
A.Other objects
B.Other methods
C.Other classes
D.Other binders
Câu 12 If you don't have the access to the source code for a class, but you want to change
the way a method of that class works, then could you use subclassing to do that that is to
extend the "bad" class and override the method with your own better code?
A.True
B.False
Câu 13 The relation between the Car and Owner or BankAccount and Customer is an
example of
A.Aggregation
B.Composition
C.Association
D.None
Câu 14 Subclassing polymorphism is sometimes called “true polymorphism”.
A.True
B.False

Downloaded by Huy Lê ([email protected])


lOMoARcPSD|34127520

Câu 15 Consider the below code and choose the correct output. public class Main { public
int a; public long b; public void test(long b) { System.out.println("long b"); } public void
test(int a) { System.out.println("int a"); } public static void main(String[] args) {
Main e=new Main(); e.test(9*1000000000); } }
A.Int a
B.Long b
C.Long a
D.Error
Câu 16 Polymorphism is one interface with __________.
A.Multiple methods
B.Single method
C.Multiple record
D.Single record
Câu 17 Interfaces are fast as they require extra indirection to find the corresponding
method in the actual class.
A.True
B.False.
Câu 18 Consider the code below and choose the correct option. class GameShape { public
void displayShape() { System.out.println("displaying shape"); } // more code } class
PlayerPiece extends GameShape { public void movePiece() { System.out.println("moving
game piece"); } // more code } public class TestShapes { public static void main
(String[] args) { PlayerPiece shape = new PlayerPiece(); shape.displayShape();
shape.movePiece(); } }

A.PlayingPiece class inherits the generic movePiece() method


B.PlayingPiece class inherits the generic displayShape() method
C.GameShape class inherits the generic displayShape() method
D.GameShape class inherits the generic movePiece() method
Câu 19 Consider the code below and choose the correct option. class GameShape { public
void displayShape() { System.out.println("displaying shape"); } // more code } class
PlayerPiece extends GameShape { public void movePiece() { System.out.println("moving
game piece"); } // more code } public class TestShapes { public static void main
(String[] args) { PlayerPiece shape = new PlayerPiece(); shape.displayShape();
shape.movePiece(); } }
A.PlayingPiece class inherits the generic movePiece() method
B.PlayingPiece class inherits the generic displayShape() method
C.GameShape class inherits the generic displayShape() method
D.GameShape class inherits the generic movePiece() method

Downloaded by Huy Lê ([email protected])


lOMoARcPSD|34127520

Câu 20 Examples of class are( choose 3)


A.White
B.Length
C.Classroom
D.Car
E.Person
Câu 21 In OOP, the concept of IS-A is based on
A.Class inheritance
B.Interface implementation.
C.Both
D.None
============================================================
Phần 2
Câu 1 What java library must be imported to get user input for the Scanner class?
answer choices
A. DecimalFormat( )
B. javax.swing.JOptionPane;
C. java.util.Scanner;
D. java.util.Random
Câu 2 What is a constructor?
A. another name for an instance variable
B. the method that creates an object, or instance, of the class
C. the return type of a method
D. the instantiation of an object
Câu 3 What does it mean when a method is static?
A. it modifies or mutates an object
B. it is private
C. it applies to the entire class, not just one object or instance
D. it is overloaded
Câu 4 What is the result of the following expression when x is 3583?
(x/10)%10
A. 3
B. 8
C. 83
D. 300

Downloaded by Huy Lê ([email protected])


lOMoARcPSD|34127520

Câu 5 GradStudent extends class Student. Which of these is NOT valid?


A. Students s = new Student()
B. Student s = new GradStudents()
C. GradStudent g = new Student()
D. GradStudent g = new GradStudent()
Câu 6 _________________ means the method has no return value.
A. void
B. static
C. concatenation
D. string
Câu 7 ___________________ variable is a variable defined in a class.
A. reference
B. instance
C. modulous
D. void
--------------------------------------------------------------------
Phần 3
Câu 1 Which of the following are the concepts of OOP?
A. Encapsulation
B. Polymorphism
C. Abstraction
D. Inheritance
Câu 2 Encapsulation is a process of wrapping of data and methods in a single unit called -----------
A. Variable
B. Functions
C. Class
D. Box
Câu 3 Which feature of OOPS derives the class from another class?
A. Inheritance
B. Data hiding
C. Encapsulation
D. Polymorphism
Câu 4 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
Câu 5 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

Downloaded by Huy Lê ([email protected])


lOMoARcPSD|34127520

Câu 6 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
Câu 7 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
Câu 8 Which definition best defines the concept of abstraction?
A. answer choices
B. Hides the important data
C. Hides the implementation and showing only the features
D. Hiding the implementation
E. Showing the important data
Câu 9 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
Câu 10 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.
-----------------------------------------------------------------------------------------

Downloaded by Huy Lê ([email protected])

You might also like