MCQs on Object-Oriented Programming | Kotlin

Object-Oriented Programming (OOP) in Kotlin focuses on concepts like inheritance, interfaces, and abstract classes. These key concepts help developers design structured and reusable code for modern applications.


Object-Oriented Programming in Kotlin: MCQs

1. Inheritance

  1. What is the purpose of inheritance in Kotlin?
    • a) Reusing code from other classes
    • b) Creating new classes
    • c) Defining new interfaces
    • d) Protecting data
  2. Which keyword is used to inherit a class in Kotlin?
    • a) extends
    • b) :
    • c) super
    • d) inherits
  3. How do you prevent a class from being inherited in Kotlin?
    • a) Use open keyword
    • b) Use final keyword
    • c) Use abstract keyword
    • d) Use sealed keyword
  4. Can a class in Kotlin inherit from multiple classes?
    • a) Yes, through multiple inheritance
    • b) No, Kotlin supports single inheritance only
    • c) Yes, if the classes are interfaces
    • d) Yes, but only from abstract classes
  5. What is true about the constructor of a class in Kotlin?
    • a) The constructor is always inherited
    • b) The constructor must be explicitly called in the subclass
    • c) Constructors are not inherited in Kotlin
    • d) Only primary constructor is inherited
  6. Which keyword is used to call the superclass constructor in Kotlin?
    • a) super()
    • b) base()
    • c) this()
    • d) parent()
  7. What will happen if you don’t declare a constructor in the subclass of a class in Kotlin?
    • a) It will automatically call the default constructor
    • b) The code will fail to compile
    • c) It will be inherited from a superclass
    • d) The superclass constructor must be explicitly called
  8. How does Kotlin handle method overriding in inheritance?
    • a) You cannot override methods in Kotlin
    • b) Methods are automatically overridden
    • c) Methods must be marked with the override keyword
    • d) Methods are abstract by default
  9. Can a method in a superclass be private and still be inherited in Kotlin?
    • a) Yes, but it must be explicitly declared
    • b) No, private methods cannot be inherited
    • c) Yes, private methods are inherited as public
    • d) Only protected methods can be inherited
  10. What does the open keyword do in Kotlin?
    • a) Allows the class or method to be overridden
    • b) Prevents the class or method from being overridden
    • c) Makes the class or method public
    • d) Initializes the class

2. Interfaces

  1. In Kotlin, how can a class implement an interface?
    • a) By using the extends keyword
    • b) By using the implements keyword
    • c) By using the : operator
    • d) By using the interface keyword
  2. What is a primary characteristic of an interface in Kotlin?
    • a) It can have both abstract and concrete methods
    • b) It can have only concrete methods
    • c) It can have only properties
    • d) It cannot have any methods
  3. Can an interface have default implementations for methods in Kotlin?
    • a) No, interfaces can have only abstract methods
    • b) Yes, using default keyword
    • c) Yes, by defining methods with a body
    • d) Only abstract classes can have default methods
  4. Can a class implement multiple interfaces in Kotlin?
    • a) No, only one interface can be implemented
    • b) Yes, but only if they don’t have conflicting methods
    • c) Yes, Kotlin supports multiple inheritance through interfaces
    • d) Yes, but only abstract classes can do this
  5. Can an interface contain properties in Kotlin?
    • a) No, interfaces cannot contain properties
    • b) Yes, but the properties must be abstract
    • c) Yes, but the properties must be final
    • d) Yes, interfaces can contain properties with getters and setters
  6. How are abstract methods defined in Kotlin interfaces?
    • a) Using the abstract keyword
    • b) Using the open keyword
    • c) Methods in interfaces are always abstract
    • d) Using the abstract and open keywords
  7. What happens if a class implements an interface but doesn’t provide an implementation for all abstract methods?
    • a) The class compiles successfully with default values for the methods
    • b) The class becomes an abstract class
    • c) The code will fail to compile
    • d) The compiler will automatically implement the missing methods
  8. How do you call the method from an interface when it is implemented in a class?
    • a) Using super.method()
    • b) Using interface.method()
    • c) Using class.method()
    • d) Directly calling method() without prefix
  9. Can an interface in Kotlin extend another interface?
    • a) No, interfaces cannot extend other interfaces
    • b) Yes, interfaces can extend other interfaces
    • c) Yes, but only abstract classes can extend interfaces
    • d) No, but interfaces can implement other interfaces
  10. How do you declare an interface in Kotlin?
    • a) class InterfaceName
    • b) interface InterfaceName
    • c) abstract class InterfaceName
    • d) sealed interface InterfaceName

3. Abstract Classes

  1. What is the purpose of an abstract class in Kotlin?
    • a) To create instances of the class
    • b) To serve as a base class for other classes
    • c) To define concrete methods
    • d) To provide a collection of objects
  2. Which keyword is used to define an abstract class in Kotlin?
    • a) abstract
    • b) sealed
    • c) interface
    • d) open
  3. Can an abstract class in Kotlin have a constructor?
    • a) Yes, but it must be explicitly defined as abstract
    • b) No, abstract classes cannot have constructors
    • c) Yes, constructors are inherited
    • d) Yes, the constructor can be defined as normal
  4. Can an abstract class have implemented methods in Kotlin?
    • a) No, abstract classes cannot have method implementations
    • b) Yes, abstract classes can have both abstract and implemented methods
    • c) Yes, abstract classes can only have implemented methods
    • d) No, all methods must be abstract
  5. What will happen if you try to create an instance of an abstract class in Kotlin?
    • a) The class will compile but cannot be instantiated
    • b) The code will fail to compile
    • c) The class will be instantiated as a default class
    • d) The object will be created as null
  6. What is the default visibility of methods in an abstract class in Kotlin?
    • a) Public
    • b) Private
    • c) Internal
    • d) Protected
  7. Can you override a method from an abstract class in Kotlin?
    • a) No, abstract class methods cannot be overridden
    • b) Yes, you must use the override keyword
    • c) Yes, but only in abstract methods
    • d) Yes, using the final keyword
  8. Can an abstract class extend another abstract class in Kotlin?
    • a) No, abstract classes cannot extend other abstract classes
    • b) Yes, abstract classes can extend other abstract classes
    • c) Yes, but the subclass must provide method implementations
    • d) No, only interfaces can extend abstract classes
  9. How do you declare an abstract method in Kotlin?
    • a) abstract fun methodName()
    • b) fun methodName()
    • c) abstract methodName()
    • d) open fun methodName()
  10. Can an abstract class implement an interface in Kotlin?
    • a) No, abstract classes cannot implement interfaces
    • b) Yes, abstract classes can implement interfaces
    • c) Yes, but only concrete classes can implement interfaces
    • d) No, only concrete classes can implement interfaces

Answers

QNoAnswer
1a) Reusing code from other classes
2b) :
3b) Use final keyword
4b) No, Kotlin supports single inheritance only
5c) Constructors are not inherited in Kotlin
6a) super()
7a) It will automatically call the default constructor
8c) Methods must be marked with the override keyword
9b) No, private methods cannot be inherited
10a) Allows the class or method to be overridden
11c) By using the : operator
12a) It can have both abstract and concrete methods
13c) Yes, by defining methods with a body
14c) Yes, Kotlin supports multiple inheritance through interfaces
15b) Yes, but the properties must be abstract
16c) Methods in interfaces are always abstract
17b) The class becomes an abstract class
18b) Using interface.method()
19b) Yes, interfaces can extend other interfaces
20b) interface InterfaceName
21b) To serve as a base class for other classes
22a) abstract
23a) Yes, but it must be explicitly defined as abstract
24b) Yes, abstract classes can have both abstract and implemented methods
25b) The code will fail to compile
26a) Public
27b) Yes, you must use the override keyword
28b) Yes, abstract classes can extend other abstract classes
29a) abstract fun methodName()
30b) Yes, abstract classes can implement interfaces

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top