OOP in Practice: Java vs C++ vs Python Quiz Quiz

Challenge yourself on object-oriented programming concepts with focus on their implementation in Java, C++, and Python. This quiz highlights differences in syntax, inheritance, encapsulation, polymorphism, and memory management, helping learners understand practical OOP techniques across these three popular languages.

  1. Inheritance Syntax Distinction

    Which of the following options correctly demonstrates single inheritance in Python for a class named Dog inheriting from Animal?

    1. class Dog -u003E Animal:
    2. class Dog(Animal):
    3. public class Dog extends Animal {
    4. class Dog : public Animal {

    Explanation: The correct syntax in Python for single inheritance is 'class Dog(Animal):', where Dog inherits from Animal. The option 'class Dog : public Animal {' is valid syntax for C++, not Python. The option 'public class Dog extends Animal {' corresponds to Java syntax. Finally, 'class Dog -u003E Animal:' is not valid in any of the three languages.

  2. Abstract Class Implementation

    In which language is it common to use the 'abstract' keyword to declare an abstract class and abstract methods?

    1. PyThon
    2. C++
    3. Java
    4. Python

    Explanation: Java uses the 'abstract' keyword to declare abstract classes and abstract methods, enforcing a contract that subclasses must implement. C++ uses 'virtual' and '= 0' to create pure virtual functions but does not use the 'abstract' keyword. Python can create abstract classes using the ABC module, not by using 'abstract'. 'PyThon' is simply a misspelling and is not a valid programming language.

  3. Default Access Modifier

    When no access modifier is specified for a member variable in a class, which language makes the variable package-private by default?

    1. Java
    2. Jaav
    3. C++
    4. Python

    Explanation: In Java, if no access modifier is specified, the member is package-private, meaning it is accessible only within its own package. In C++, members are private by default, while in Python, all variables are public unless prefixed with underscores. 'Jaav' is a typo and not a programming language.

  4. Memory Management in OOP

    Which language among Java, C++, and Python requires explicit memory deallocation using commands like 'delete'?

    1. Java
    2. Ctt++
    3. Python
    4. C++

    Explanation: C++ requires explicit memory management with commands like 'delete' to free up dynamically allocated memory. In contrast, both Java and Python use automatic garbage collection and do not require such explicit deallocation. 'Ctt++' is an incorrect and non-existent language.

  5. Method Overloading Capability

    Which of these languages does NOT directly support method overloading based strictly on parameter types or counts in its class definitions?

    1. Java
    2. Pyhton
    3. C++
    4. Python

    Explanation: Python does not directly support method overloading based on parameter types or counts; recent versions let you use function overloading via decorators but not in the traditional way. Java and C++ both support method overloading by allowing multiple methods with the same name but different parameters. 'Pyhton' is a common typo and not a programming language.