Challenge - 5 Problems
OOP Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
π§ Conceptual
intermediate2:00remaining
Why use encapsulation in OOP?
Which of the following best explains why encapsulation is used in object-oriented programming?
Attempts:
2 left
π‘ Hint
Think about how encapsulation helps keep data safe inside an object.
β Incorrect
Encapsulation hides the internal state of an object and only exposes controlled ways to access or modify it. This protects data and helps maintain integrity.
β Predict Output
intermediate2:00remaining
Output of inheritance example
What is the output of this Java code?
Java
class Animal { void sound() { System.out.println("Some sound"); } } class Dog extends Animal { void sound() { System.out.println("Bark"); } } public class Main { public static void main(String[] args) { Animal a = new Dog(); a.sound(); } }
Attempts:
2 left
π‘ Hint
Look at which method is called when an Animal reference points to a Dog object.
β Incorrect
Even though the reference type is Animal, the actual object is Dog. Java calls the overridden method in Dog, so it prints "Bark".
β Predict Output
advanced2:00remaining
Polymorphism with method overloading
What will this Java program print?
Java
class Calculator { int add(int a, int b) { return a + b; } int add(int a, int b, int c) { return a + b + c; } } public class Main { public static void main(String[] args) { Calculator calc = new Calculator(); System.out.println(calc.add(2, 3)); System.out.println(calc.add(1, 2, 3)); } }
Attempts:
2 left
π‘ Hint
Check how many arguments each add method takes.
β Incorrect
Method overloading allows multiple methods with the same name but different parameters. The calls match the correct method signatures, so outputs are 5 and 6.
π§ Conceptual
advanced2:00remaining
Why use abstraction in OOP?
Which statement best describes the purpose of abstraction in object-oriented programming?
Attempts:
2 left
π‘ Hint
Think about how abstraction simplifies interaction with objects.
β Incorrect
Abstraction hides complex implementation details and shows only what is necessary, making it easier to use and understand objects.
π§ Conceptual
expert3:00remaining
Main advantage of using OOP in large software projects
What is the main advantage of using object-oriented programming in large software projects?
Attempts:
2 left
π‘ Hint
Think about how OOP helps manage complexity in big programs.
β Incorrect
OOP organizes code into objects that bundle data and behavior, making large projects easier to maintain, reuse, and understand.