Tuesday, June 23, 2009

Inheritance Example

Inheritance in Java
Inheritance is a compile-time mechanism in Java that allows you to extend a class (called the base class or superclass) with another class (called the derived class or subclass).

class inheritance - create a new class as an extension of another class, primarily for the purpose of code reuse. That is, the derived class inherits the public methods and public data of the base class. Java only allows a class to have one immediate base class, i.e., single class inheritance.

For class inheritance, Java uses the keyword extends

public class derived-class-name extends base-class-name {
// derived class methods extend and possibly override
// those of the base class
}

No comments:

Post a Comment

 
Your Ad Here ]]>