Question: package com.mac 1 9 0 . inheritance; / * Inheritance is used whenever an object of a class can be considered as also an object

package com.mac190.inheritance;
/*
Inheritance is used whenever an object of a class can be considered as also an object
of another class. Example: I have a class Animal, you want to design a class Dog, A Dog IS
an animal, then the class Dog should be designed using inheritance from class Animal.
When inheritance is used a class inherits all member variables and methods of the inherited class.
Still private members of the parent class cannot be accessed directly by the inherited/child class.
If an inherited class needs to access member variables of a parent class, then you can use protected.
protected can be accessed by inherited class but not the public.
Let's have an example:
create a class animal that has the following:
color, age, species, diet
toString, equals
method speak() to display I don;t know how to speak yet!.
*/
public class Animal {
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!