Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Terminology (When in Rome Stuff)

 

Inheritance

Concrete Class

implements Keyword

super Keyword

Method Overloading

Object Class

Abstract Class

Single Inheritance

Is A Relationship

Field

Parent Class

Interface

Multiple Inheritance

Has A Relationship

final Keyword

Derived Class

extends Keyword

Constructor

Method Overriding

 

Inheritance

♦  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.

 

Object Class

♦  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).

 

Derived or Subclass

♦  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.

Concrete Class

♦  A class in which all methods are defined

♦  You can create an object of a concrete class.

 

Abstract 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

     {

     }
}

 

Interface Class

♦  A class in which no methods are defined

♦  You cannot create an object of an interface class

♦  Example

     public interface Working
    {
        public void work();
    }

 

Extends Keyword

♦  Indicates inheritance in which a concrete class is being inherited

 

Implements Keyword

♦  Indicate inheritance in which either an interface or abstract class is being inherited

 

Single Inheritance

♦  Inheritance in which a class inherits directly from only one superclass

 

Multiple Inheritance

♦  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


 

Constructor

♦  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.

 

Super

♦  Keyword that indicates the constructor immediately above the one using it is being called

 

Is A Relationship

♦  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

 

Has A Relationship

♦  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.

Method Overriding

 

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.

 

Field

 

Data - instance variables

 

Method Overloading

Methods with same name but different signatures

 

final Keyword

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