Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

allows us to create new classes based on existing classes polymorphism Inheritan

ID: 3695616 • Letter: A

Question

allows us to create new classes based on existing classes polymorphism Inheritance The copy construction function overloading None of these The term means the ability to take many forms encapsulate Inheritance polymorphism None of these When you drive a class from an existing class you add new data and functions must never may None of the above In the following statement class car: protected vehicle is the derived class vehicle car protected cannot be determined None of these In the following statement class car: protected vehicle is the base class vehicle class public car none of these also known as the address operator, returns the memory address of a variable point(!) percent sign(%) apprehend(&) None of these

Explanation / Answer

18.inheritance

In class-based programming, inheritance is done by defining new classes as extensions of existing classes: the existing class is theparent class and the new class is the child class. If a child class has only one parent class, this is known as single inheritance, while if a child class can have more than one parent class, this is known as multiple inheritance. This organizes classes into a hierarchy, either a tree (if single inheritance) or lattice (if multiple inheritance).

The defining feature of inheritance is that both interface and implementation are inherited; if only interface is inherited, this is known as interface inheritance or subtyping. Inheritance can also be done with out class

19.D

Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

Any Java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object.

It is important to know that the only possible way to access an object is through a reference variable. A reference variable can be of only one type. Once declared, the type of a reference variable cannot be changed.

20.must

The topics covered in later subsections of this section are relatively advanced aspects of object-oriented programming. Any programmer should know what is meant by subclass, inheritance, and polymorphism. However, it will probably be a while before you actually do anything with inheritance except for extending classes that already exist. In the first part of this section, we look at how that is done.

In day-to-day programming, especially for programmers who are just beginning to work with objects, subclassing is used mainly in one situation: There is an existing class that can be adapted with a few changes or additions. This is much more common than designing groups of classes and subclasses from scratch. The existing class can be extended to make a subclass. The syntax for this is

21.car

As the Vehicle is abstract, it’s legal to override only two methods from the Moveable interface. And the move() method must be implemented by the first non-abstract in the inheritance tree.

Suppose that Car is a subclass of Vehicle, so we have an inheritance tree like this:

                Moveable > Vehicle > Car

Since Car is a non-abstract class, it must implement the move() method of the Moveable interface:

1

2

3

4

5

public class Car extends Vehicle {

    public void stop() {

        System.out.print("Moving by engine...");

    }

}

As the Vehicle is abstract, it’s legal to override only two methods from the Moveable interface. And the move() method must be implemented by the first non-abstract in the inheritance tree.

Suppose that Car is a subclass of Vehicle, so we have an inheritance tree like this:

                Moveable > Vehicle > Car

Since Car is a non-abstract class, it must implement the move() method of the Moveable interface:

1

2

3

4

5

public class Car extends Vehicle {

    public void stop() {

        System.out.print("Moving by engine...");

    }

}

22. vechicle

1

2

3

4

5

6

7

public interface Moveable {

    public void start();

    public void stop();

    public void move();

}

1

2

3

4

5

6

7

public interface Moveable {

    public void start();

    public void stop();

    public void move();

}

23.&

1

2

3

4

5

public class Car extends Vehicle {

    public void stop() {

        System.out.print("Moving by engine...");

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote