OOP Quiz - Languages Kotlin
Free practice quiz: OOP (Languages Kotlin). 53 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 53 questions freeSample questions
In Kotlin, which keyword is used to define a class?
- class
- object
- data class
- abstract class
Show answer
Answer: A. class
The `class` keyword is the fundamental way to declare a new class in Kotlin. `object` is for singletons, `data class` is for holding data, and `abstract class` is for classes that cannot be instantiated directly.
Which Kotlin keyword is used to refer to the current instance of a class?
- this
- self
- me
- current
Show answer
Answer: A. this
`this` is the keyword used in Kotlin to refer to the current instance of the class within its own methods and constructors.
What is method overloading in the context of OOP?
- Defining multiple methods with the same name but different parameter lists within the same class.
- Allowing a subclass to provide a specific implementation of a method already defined in its superclass.
- Hiding the implementation details of a method.
- Creating methods that can return different types of data.
Show answer
Answer: A. Defining multiple methods with the same name but different parameter lists within the same class.
Method overloading allows a class to have multiple methods with the same name, provided they have different signatures (number, type, or order of parameters). This is a form of compile-time polymorphism.
If a class `A` implements interface `I`, and interface `I` declares an abstract function `doSomething()`, what must the class `A` do?
- Provide a concrete implementation for `doSomething()`.
- Declare `doSomething()` as `private`.
- Declare class `A` as `abstract`.
- Call `super.doSomething()` within class `A`.
Show answer
Answer: A. Provide a concrete implementation for `doSomething()`.
Implementing an interface requires providing concrete implementations for all its abstract members. Failure to do so would result in a compile-time error unless the implementing class itself is declared abstract.
What is 'abstraction' in OOP, and why is it important?
- Abstraction is about hiding complex implementation details and showing only essential features. It's important for managing complexity, improving maintainability, and allowing for flexible design.
- Abstraction means creating multiple instances of the same class.
- Abstraction is the process of inheriting properties from a parent class.
- Abstraction refers to the ability of an object to take on many forms.
Show answer
Answer: A. Abstraction is about hiding complex implementation details and showing only essential features. It's important for managing complexity, improving maintainability, and allowing for flexible design.
By abstracting away complexities, developers can focus on the 'what' an object does without getting bogged down in the 'how'. This leads to cleaner, more modular code.