OOP Quiz - Languages Kotlin
Free practice quiz: OOP (Languages Kotlin). 53 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This Languages Kotlin practice quiz has 53 multiple-choice questions on OOP, and 53 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 53 questions, freeSample questions
In Kotlin, which keyword is used to define a 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?
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?
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?
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?
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.
More questions in this quiz
Answers and explanations are in the full quiz.
- What is encapsulation in OOP?
- Which of the following best describes inheritance in Kotlin?
- In Kotlin, what does the `abstract` keyword signify when applied to a class?
- Polymorphism in OOP allows an object to:
- What is the primary purpose of an `interface` in Kotlin?
- When a class implements an interface in Kotlin, what is required of the implementing class?
- What is a constructor in Kotlin?
- How is a primary constructor defined in a Kotlin class?
- What is the purpose of the `init` block in a Kotlin class?
- What is a 'data class' in Kotlin primarily used for?
- In Kotlin, what is the purpose of the `object` keyword when used for a declaration?
- Consider a class `Animal` and a class `Dog` that inherits from `Animal`. If `Dog` overrides a method `makeSound()` from `Animal`, which OOP principle is being demonstrated?
- Which keyword in Kotlin is used to prevent a class from being inherited?
- What does the `open` keyword signify for a class in Kotlin?
- In Kotlin, if a class has a primary constructor with parameters, and you don't explicitly define a secondary constructor, how are those parameters typically used?
- What is an abstract property in Kotlin?
- Which of the following is NOT an OOP principle?
- Consider a Kotlin class `Car` with a property `color`. How would you declare a constructor that takes `color` as an argument and initializes this property?
- What is the difference between `val` and `var` in Kotlin class properties?
- What is method overriding in the context of OOP?
- In Kotlin, what is the `super` keyword used for?
- When is it appropriate to use a `data class` in Kotlin?
- What does the concept of 'tight coupling' refer to in OOP?
- Which of the following Kotlin constructs best exemplifies 'abstraction'?
- In Kotlin, what is the purpose of a `companion object`?
- When might you use a `sealed class` in Kotlin?
- Consider the following Kotlin code: `open class Vehicle { open fun start() { /* ... */ } } class Car : Vehicle() { override fun start() { /* ... */ } }`. What is `override` used for here?
- What is a property delegate in Kotlin, and how does it relate to OOP?
- What is the main benefit of using composition over inheritance?
- In Kotlin, what is the role of the `private` keyword for class members?
- Which Kotlin modifier allows a member to be accessed from its own class, subclasses, and other classes within the same module?
- What is the significance of the `protected` visibility modifier in Kotlin?
- What is a constructor initializer list in Kotlin, and when is it used?
- Which statement accurately describes the relationship between `abstract class` and `interface` in Kotlin?
- What is the concept of 'loose coupling' in OOP, and how is it achieved?
- In Kotlin, how does a `secondary constructor` differ from a `primary constructor`?
- What is the primary purpose of using `inheritance` in object-oriented programming?
- Consider a Kotlin class `Shape` with an abstract property `area: Double`. A subclass `Circle` inherits from `Shape`. What must `Circle` do?
- Which Kotlin keyword is used to achieve encapsulation by marking a member as inaccessible outside its containing class?
- What is the difference between an abstract class and an interface in terms of constructors?
- In Kotlin, if you have a class `Engine` and a class `Car` where `Car` 'has-a' `Engine`, which OOP concept is this an example of?
- What does it mean for a method in Kotlin to be `final` by default?
- Which Kotlin keyword is used to indicate that a method *must* be implemented by concrete subclasses?
- What is the primary characteristic of a 'singleton' object in OOP?
- In Kotlin, how do you specify that a class can only be subclassed by classes defined within the same file or module?
- What is a 'getter' and 'setter' in the context of Kotlin properties, and how do they relate to encapsulation?
- What is a potential drawback of excessive use of inheritance in OOP?
- In Kotlin, when you define a class with a primary constructor like `class Person(val name: String, var age: Int)`, what does this implicitly create?