In: Computer Science
If the class Parrot extends the class Bird, what can't be said about the classes?
Select one answer:
A. The Parrot class has access to the Parrot methods
B. The Parrot class has access to the Bird methods
C. The Bird class has access to the Bird methods
D. The Bird class has access to the Parrot methods
Answer:
D. The Bird class has access to the Parrot methods
Explanation:
Inheritance is the process where one class acquires the properties or methods of another class. "extends" is a keyword that is used to inherit the properties of a class. The syntax is as follows:
class Super {
.....
.....
}
class Sub extends Super {
.....
.....
}
The class that inherits from another class is called a subclass or child class. The class being inherited is called a superclass or parent class. The subclass extends the superclass.
In the question above, class Parrot extends the class Bird. Therefore bird class is the parent/super class and parrot class is the child/sub class.
So parrot class will have access to its own class methods and along with that the methods of the bird superclass since it has inherited them.
The bird class will have access to its own methods but won't be able to access the methods of parrot class since it is not the inherited class. Infact it is the parent class and methods are inherited from it.