A big part of writing code, is writing reusable code. Why? Well, because you don't have to write as much. The thing I like most about programming is, if done correctly, you don't have to do the tedious task of doing the same thing over, over, and over again.

In most OOP languages, or Object Orient Programming languages, you are given the ability to use inheritance. The term inheritance is just like it sounds. You can write classes that inherit the attributes and methods of parent classes. Just like you inherited genes from your mother.

There are two types of inheritance. Single inheritance, and Multiple inheritance.

With single inheritance, child classes can only inherit attributes and methods from one parent class. With multiple inheritance, child classes can inherit attributes and methods from multiple parent classes.

What languages support single inheritance? Java, PHP (5.0+), C++, C#, VB, and basically any modern OOP language. What languages support multiple inheritance? C++ is the only one I know of. In my opinion, only make use of multiple inheritance if you really know what you're doing. Otherwise, things can get messy real quick.

Enough with all the jibber jabber. Lets watch some videos:

Below is similar source code featured in the videos, if anyone is interested.

Person Class:

public class Person
{
    //These feilds can now be accessed by
    //Person and child classes ONLY. They
    //still cannot be changed from a created
    //object without going through a method call.
    //Hence, they are 'protected'.
    protected int age;
    protected String name;
    
    //Default Constructor
    public Person()
    {
        this.name = "John Doe";
        this.age = 0;
    }
    
    //Overloaded Constructor
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;  
    }
    
    public void setAge(int age) {
        this.age = age;   
    }
    
    public int getAge() {
        return this.age;   
    }
    
    public String getName() {
        return this.name;   
    }
    
    public String toString() {
        String returnString = new String("Hi, I'm " + this.name + ", and I'm " + this.age + " years old!nn");       
        return returnString;
    }
}

Employee Class:

public class Employee extends Person
{
    //Since an Employee IS A Person,
    //I don't have to make any name and age
    //attributes! Yay.
    private String department;
    
    //Default Constructor
    public Employee()
    {
        //Make a call to Person's default constructor
        super();
        this.department = "Sales :(";
    }
    
    //Overloaded Constructor
    public Employee(String name, int age, String department) {
        //Make a call to Person's overloaded constructor
        super(name, age);
        this.department = department;
    }
    
    public String getDepartment() {
        return this.department;
    }
   
    public void setDepartment(String department) {
        this.department = department;
    }
   
    public String toString() {
        String returnString = new String("I'm " + this.name + ", and I belong to the " + this.department + " department!nn");
        return returnString;
    }
}

Customer Class:

public class Customer extends Person
{
    //Since a Customer IS A Person,
    //I don't have to make any name and age
    //attributes! Yay.
    private String customerID;

    //Default Constructor
    public Customer()
    {
        //Make a call to Person's default constructor
        super();
        this.customerID = "N/A";
    }
    
    //Overloaded Constructor
    public Customer(String name, int age, String customerID) {
        //Make a call to Person's overloaded constructor
        super(name, age);
        this.customerID = customerID;
    }
    
    public String getCustomerID() {
        return customerID;
    }
   
    public void setCustomerID(String customerID) {
        customerID = customerID;
    }
    
    public String toString() {
        String returnString = new String("I'm " + this.name + ", and I'm a customer.  See, my customer ID is: " + this.customerID + "nn");
        return returnString;
    }
}

Main Driver that uses Classes:

public class main
{
    public static void main(String[] args) {
        Person rob = new Person("Rob", 22);
        System.out.println(rob);
        
        Employee john = new Employee("John", 44, "IT");
        System.out.println(john);
        
        Customer lauren = new Customer("Lauren", 19, "15D8A7R2");
        System.out.println(lauren);
    }
}