Java: KIỂM TRA KIẾN THỨC OOP


Khóa học qua video:
Lập trình Python All Lập trình C# All SQL Server All Lập trình C All Java PHP HTML5-CSS3-JavaScript
Đăng ký Hội viên
Tất cả các video dành cho hội viên

1. Which of the following is not a principle of OOP?
 A. Encapsulation
 B. Polymorphism
 C. Abstraction
 D. Compilation

2. What is an object in Java?
 A. An instance of a class
 B. A function
 C. A data type
 D. A memory location

3. What keyword is used to create an object in Java?
 A. class
 B. new
 C. create
 D. this

4. Which of the following is true about constructors in Java?
 A. A constructor has a return type
 B. A constructor name must match the class name
 C. A constructor cannot have parameters
 D. A class cannot have multiple constructors

5. Which keyword is used for inheritance in Java?
 A. extends
 B. implements
 C. inherits
 D. super

6. What happens if a class does not explicitly extend another class?
 A. It extends Object by default
 B. It cannot be instantiated
 C. It must implement an interface
 D. It will cause a compilation error

7. What is method overloading?
 A. Having multiple methods with the same name but different parameters
 B. Having multiple classes with the same name
 C. Overriding a method in the superclass
 D. Using super in a method

8. What is method overriding?
 A. Redefining a method of a superclass in a subclass
 B. Creating a new method with the same name
 C. Using multiple methods with different return types
 D. Declaring a method as private

9. What does encapsulation achieve?
 A. Hiding data and restricting direct access
 B. Making all variables public
 C. Allowing multiple inheritance
 D. Preventing object creation

10. How do you achieve encapsulation in Java?
 A. Using private variables and public getter/setter methods
 B. Declaring all methods static
 C. Using final for all methods
 D. Using super keyword

11. Which keyword is used to declare an abstract class?
 A. abstract
 B. interface
 C. extends
 D. implements

12. Can an abstract class have constructors?
 A. Yes
 B. No
 C. Only if all methods are abstract
 D. Only if it extends another class

13. What keyword is used to declare an interface?
 A. interface
 B. abstract
 C. extends
 D. implements

14. What can an interface contain?
 A. Only abstract methods
 B. Only instance variables
 C. Both abstract and default methods
 D. Both constructors and abstract methods

15. What is the purpose of the static keyword?
 A. To create a shared class variable or method
 B. To prevent method overriding
 C. To restrict object creation
 D. To create immutable variables

16. What does the final keyword do when applied to a variable?
 A. Makes the variable constant (unchangeable)
 B. Prevents method overriding
 C. Prevents class inheritance
 D. Forces garbage collection

17. Can a constructor be overridden?
 A. Yes
 B. No
 C. Only if it has a return type
 D. Only if it is final

18. What happens if a class does not have a constructor?
 A. Java provides a default constructor
 B. The class cannot be instantiated
 C. Compilation error occurs
 D. All methods become static

19. Which keyword is used for exception handling?
 A. try
 B. throw
 C. catch
 D. All of the above

20. Which exception is thrown when dividing by zero?
 A. NullPointerException
 B. ArithmeticException
 C. IndexOutOfBoundsException
 D. IOException

21. How many interfaces can a Java class implement?
 A. Only one
 B. Multiple
 C. None
 D. It depends on the compiler

22. What does Reflection in Java allow?
 A. Accessing class information at runtime
 B. Overriding final methods
 C. Modifying private variables from outside
 D. Both A and C

23. What does the @Override annotation indicate?
 A. A method is overriding a superclass method
 B. A method is final
 C. A method is private
 D. A method is static

24. What happens if a subclass does not override an abstract method from the superclass?
 A. The subclass must also be abstract
 B. The program will run normally
 C. Compilation error occurs
 D. Nothing happens

25. Can a Java class extend multiple classes?
 A. No
 B. Yes
 C. Only if using implements
 D. Only if the classes are final

26. What is an anonymous class in Java?
 A. A class without a name, defined and instantiated in a single expression
 B. A class with no methods
 C. A class with only static methods
 D. A class that cannot be inherited

27. What is a key difference between an abstract class and an interface?
 A. An abstract class can have constructors, but an interface cannot
 B. An abstract class cannot have methods, but an interface can
 C. An interface can have private fields, but an abstract class cannot
 D. An interface cannot be implemented by multiple classes

28. If a static method is redefined in a subclass, what happens?
 A. It hides the superclass method, rather than overriding it
 B. It overrides the superclass method
 C. A compilation error occurs
 D. A runtime error occurs

29. What is the purpose of the super keyword in Java?
 A. To call a superclass constructor or method
 B. To create a new instance of a class
 C. To access a subclass’s private fields
 D. To declare a constant variable

30. What is a default method in an interface?
 A. A method with a default implementation in an interface
 B. A method that must be overridden in the implementing class
 C. A method that cannot have a body
 D. A method that is always private

» Tiếp: Ngoại lệ là gì?
« Trước: Lớp lồng nhau (Nested Classes)
Khóa học qua video:
Lập trình Python All Lập trình C# All SQL Server All Lập trình C All Java PHP HTML5-CSS3-JavaScript
Đăng ký Hội viên
Tất cả các video dành cho hội viên
Copied !!!