Inheritance in Java Quiz
30 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the dispContact() method in the Person class?

  • To set the contact information of a `Person` object
  • To get the contact information of a `Person` object
  • To print the contact information of a `Person` object (correct)
  • To delete the contact information of a `Person` object
  • Which of the following is a correct statement about the visibility of class members in Java inheritance?

  • Public class members are not accessible by subclasses
  • Private class members are accessible by subclasses
  • Protected class members are accessible by subclasses (correct)
  • Default class members are accessible by subclasses
  • What is the relationship between the Person, Employee, and Customer classes in the given code?

  • The `Employee` and `Customer` classes inherit from the `Person` class (correct)
  • The `Person` class inherits from the `Employee` and `Customer` classes
  • The `Employee` and `Customer` classes are independent of the `Person` class
  • The `Employee` class inherits from the `Customer` class, and both inherit from the `Person` class
  • What is the purpose of the empID and designation fields in the Employee class?

    <p>To store the employee's identification and job title</p> Signup and view all the answers

    What is the purpose of the customerID and invoiceNo fields in the Customer class?

    <p>To store the customer's identification and invoice number</p> Signup and view all the answers

    What is the significance of the statement 'OOP Java is the easiest, scoring and my favorite subject' in the given text?

    <p>It is a statement made by a student about their experience with Java programming</p> Signup and view all the answers

    What does polymorphism refer to in object-oriented programming?

    <p>The ability of an object to take on many forms</p> Signup and view all the answers

    Which access modifier allows a class to be accessed from anywhere?

    <p>Public</p> Signup and view all the answers

    Why is multiple and hybrid inheritance not supported in Java?

    <p>To avoid the Diamond Problem</p> Signup and view all the answers

    What is the superclass of every other class in Java?

    <p>Object</p> Signup and view all the answers

    Can a class extend more than one class in Java?

    <p>No, Java does not support multiple inheritance</p> Signup and view all the answers

    What does the term 'Polymorphism' mean in object-oriented programming?

    <p>The ability of a method to do different things based on the object calling it</p> Signup and view all the answers

    What is the purpose of the r variable in the code snippet?

    <p>To store a reference of type <code>A</code></p> Signup and view all the answers

    What is the output of the code snippet?

    <p>inside class A, inside class B, inside class C</p> Signup and view all the answers

    What is the purpose of the if statement in the MyProg class?

    <p>To assign the appropriate <code>Game</code> object to the <code>g</code> variable based on user input</p> Signup and view all the answers

    What is the purpose of the type() method in the Game class and its subclasses?

    <p>To print the type of the game</p> Signup and view all the answers

    What is the relationship between the Game class and its subclasses?

    <p>The <code>Game</code> class and its subclasses are all concrete classes</p> Signup and view all the answers

    What is the purpose of the Scanner object in the MyProg class?

    <p>To read user input and store it in the <code>op</code> variable</p> Signup and view all the answers

    Which type of polymorphism is achieved through method overloading in Java?

    <p>Compile-time Polymorphism</p> Signup and view all the answers

    In method overriding, what relationship must exist between the classes containing the overridden method?

    <p>IS-A (Inheritance) relationship</p> Signup and view all the answers

    What is the main advantage of dynamic method dispatch in Java?

    <p>Enables run-time polymorphism</p> Signup and view all the answers

    Which type of polymorphism is associated with dynamic method dispatch in Java?

    <p>Run-time Polymorphism</p> Signup and view all the answers

    How does method overloading differ from method overriding?

    <p>Method overloading uses different parameter types or number of parameters; overriding uses the same parameter types.</p> Signup and view all the answers

    Why does Java prohibit assigning a parent class object reference to a child class object directly?

    <p>To avoid ambiguity in method resolution during dynamic method dispatch.</p> Signup and view all the answers

    What is the purpose of the VehicleInterface in the given code?

    <p>To define a contract that must be implemented by any class representing a vehicle</p> Signup and view all the answers

    What is the significance of the implements keyword in the CarClass declaration?

    <p>It forces <code>CarClass</code> to provide implementations for all methods defined in <code>VehicleInterface</code></p> Signup and view all the answers

    What is the purpose of the line VehicleInterface CarClass c = new CarClass(); in the DemoInterface class?

    <p>It creates a new instance of <code>CarClass</code> and assigns it to a variable of type <code>VehicleInterface</code></p> Signup and view all the answers

    What is the purpose of the final keyword in the declaration int a = 10; within the VehicleInterface?

    <p>It makes the variable <code>a</code> constant and unchangeable</p> Signup and view all the answers

    What is the output of the given code?

    <p>Left</p> Signup and view all the answers

    Which statement is true about methods declared in an interface?

    <p>They are implicitly <code>public</code> and <code>abstract</code></p> Signup and view all the answers

    More Like This

    Use Quizgecko on...
    Browser
    Browser