Subclass Rules

How do these things work?

Subclass

A subclass is a stem from a superclass that can access the methods written into the superclass

Rules

-A subclass inherits all the members fields, methods, and nested classes from its superclass.

-Constructors are not considered members and are not automatically inherited by a subclass

-The constructor of the super class can be invoked from the subclass to use the constructor

Example:

public class Monkey{

public String color;

public int length;


public Monkey(String color,int length)


public void setColor(String fur){

color=fur;}

public void setLength(int measurement){

length=measurement;}

}

public class Orangutan extends Monkey{

public int handSize;

public Orangutan(String color, int length, int handSize){

super(color, length);}

public void setHand(int checkHand){

handSize=checkHand;}

}

Big image