Terminology (When in Rome Stuff)
♦ The capability of a class to use the properties and methods of another class while adding its own functionality.
♦ An example of where this could be useful is with an employee records system.
♦ You could create a generic employee class with states and actions that are common to all employees.
♦ Then more specific classes could be defined for salaried, commissioned and hourly employees.
♦ The concept of inheritance greatly enhances the ability to reuse code as well as making design a much simpler and cleaner process.

♦ The Object class is the highest superclass (i.e.. root class) of Java.
♦ All other classes are subclasses (children or descendants) inherited from the Object class.
♦ The Object class includes methods such as

Parent, or Base, or Superclass
♦ The generic class is known as the parent (or superclass or base class).
♦ Classes that inherit from the base class are referred to as children (or subclasses or derived classes).
♦ Example
//implementations not shown
public class Animal
{
}
public class Mammal extends Animal
{
}
public class Reptile extends Animal
{
}
public class Dog extends Mammal
{
}
Now based on the above example, In Object Oriented terms following are true:
Animal is the superclass of Mammal class.
Animal is the superclass of Reptile class.
Mammal and Reptile are sub classes of Animal class.
Dog is the subclass of both Mammal and Animal classes.
The Things You Can Do in a Subclass Include
The inherited variables can
be used directly, just like any other variables.
The inherited methods can
be used directly as they are.
You can write a new method
in the subclass that has the same signature as the one in the superclass,
thus overriding it.
You can declare new
variables in the subclass that are not in the superclass.
You can declare new methods
in the subclass that are not in the superclass.
♦ A class in which all methods are defined
♦ You can create an object of a concrete class.
♦ A class in which at least one method is undefined
♦ You cannot create an object of an abstract class.
♦ Example
public abstract class Animal
// class is abstract
{
private String name;
public Animal(String nm) //
constructor method
{
name=nm;
}
public String getName()
// regular method
{
return name;
}
public abstract void speak();
// abstract method
{
}
}
♦ A class in which no methods are defined
♦ You cannot create an object of an interface class
♦ Example
public interface Working
{
public void work();
}
♦ Indicates inheritance in which a concrete class is being inherited
♦ Indicate inheritance in which either an interface or abstract class is being inherited
♦ Inheritance in which a class inherits directly from only one superclass

♦ Inheritance in which a class inherits directly from more than one superclass
♦ Java does not support multiple inheritance unless all the classes inherited from are interface classes

♦ Method with same name as the class and no return type
♦ Can take parameters (parameterized) or no parameters (default)
♦ Each class should have at least 2 constructors (ones listed above)
♦ The constructor is called automatically when an object of the class is created.
♦ Keyword that indicates the constructor immediately above the one using it is being called
♦ When class B inherits from class A, we say that this is an "Is A" relationship. Class B is a Class A
♦ Example
Ford class inherits from Vehicle class. Therefore, we say that Ford "is a" Vehicle
♦ When an object of class B is created inside class A, this is a "Has A" relationship.
♦ This is not called inheritance, it is called Composition
♦ Example
Inside Vehicle class an object of Carburetor class is created. We say that Vehicle "Has A" Carburetor. It is not true that Vehicle
Is A Carburetor.
In a class hierarchy, when a
method in a subclass has the same return type and signature as a method in
its superclass, then the method in the subclass is said to override the
method in the superclass. When an overridden method is called from within a
subclass, it will always refer to the version of that method defined by the
subclass.
Data - instance variables
Methods with same name but different signatures
Variables:
A java variable can be declared using the keyword final. Then the final variable can be assigned only once.
Classes:
A java class cannot be sub classed - you cannot inherit from a class declared final