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

15-18 Which of the following is true regarding subclasses? A subclass inherits m

ID: 3807614 • Letter: 1

Question

15-18

Which of the following is true regarding subclasses? A subclass inherits methods from its superclass but not instance variables A subclass inherits instance variables from its superclass but not methods. A subclass inherits methods and instance variables from its superclass. A subclass does not inherit methods or instance variables from its superclass. Consider the following interface and class: What is the minimum set of methods that a developer must implement in order to successfully compile the Ford class? public interface car (double get Price (): int getModel ():} public class Ford implements Car, Comparable

Explanation / Answer

15. Which of the following is true regarding subclasses?

a. A subclass inherits methods from its superclass but not instance variables

b. A subclass inherits instance variables from its superclass but not methods

c. A subclass inherits methods and instance variables from its superclass

d. A subclass does not inherit methods or instance variables from its superclass

Answer: c. A subclass inherits methods and instance variables from its superclass

When class is derived from another, the subclass can access all members of its super class, by the term all the members we mean both instance variables and methods.

16. Consider the following interface and class

What is the minimum set of methods that a developer must implement in order to successfully compile the Ford class?

public interface Car{

double getPrice();

int getModel();

}

Public class Ford implements Car, Comparable<Car>{

<required methods go here>

}

What is the minimum set of methods that a developer must implement in order to successfully compile the Ford class?

a. getPrice(), getModel(), compareTo(Car a)

b. getPrice(), getModel()

c. getPrice(), getModel(), equals(student s), toString()

d. No methods would need to be implemented

e. getPrice(), getModel(), compareTo(), equals(Car c), toString()

Answer: a. getPrice(), getModel(), compareTo(Car a)

When a class implements one or more interfaces, all the methods in the interfaces has to be defined in the class implementing them.

In the above example, the Ford calss is implementing two intefaces Car and Comparable,

The interface Car has two methods getModel() and getMethod() while the Comparable interface has one method compareTo(), hence for the Ford class to compile successfully we need to implement all the three methods.

17. What must a subclass do to modify a private superclass instance variables?

a. The subclass must simply use the name of the superclass instance variable.

b. The subclass must declare its own instance variable with the same name as the superclass instance variable

c. The subclass must use a public method of the superclass (if it exits) to update the superclass’s private instance variable.

d. The subclass must have its own public method to update the superclass’s private instance variable.

Answer: c. the subclass must use a public method of the superclass (if it exits) to update the superclass’s private instance variable.

When we are deriving a class from another the derived class will be able to access the public methods and variables of the super class. In order to access the private instance variable we need to take help of the public methods of the super class.

18. Which of the following statements about classes is true?

a. You can create an object from a concrete class, but not from an abstract class.

b. You can create an object from an abstract class, but not from a concrete class.

c. You cannot have an object reference whose type is an abstract class.

d. You cannot create subclasses from abstract classes.

Answer: a. You can create an object from a concrete class, but not from an abstract class.

A concrete class is a normal Java class to which objects can be created. An abstract class are classes which are prefixed by the keyword abstract, these classes may or may not have abstract methods. Abstract classes cannot be instantiated, which means objects cannot be created for abstract classes

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote