2. INHERITANCE
• Inheritance is the reusability of predefined functionality.
• Existing class is called superclass (base class in C++)and new class is called subclass (derived class in C++).
• Inheritance is also called Specialization because subclass can modify the behavior of its superclass
appropriately to that subclass.
• Direct superclass is the superclass from which subclass explicitly inherits.
• Indirect superclass is any class above the direct superclass in class hierarchy.
• In Java, class hierarchy begins with class Object (in package java.lang), which every class in Java directly or
indirectly extends.
• Java supports only single inheritance, in which each class is derived from exactly one direct superclass. It
does not support multiple inheritance.
Instructor: Tanzila Kehkashan
2
3. INHERITANCE
A superclass’s
• Public members are accessible wherever the program has
reference to an object of that superclass or one of its superclass.
• Private members can be accessed directly only within the
superclass’s declaration.
• Protected members have an inheritance level of protection
between public and private access. They can be accessed by
members of superclass and subclass and other classes in same
package.
• A superclass’s private methods are hidden in its subclass and can
be accessed only through the public or protected methods inherited
from the superclass.
Relationship between superclass & subclass
• A subclass can invoke a constructor of its superclass by using the
keyword super followed by a set of parentheses containing the
superclass constructor arguments. This must appear as the first
statement in the subclass’s constructor body.
Example
public class person
{
}
public class student extends person
{
}
public class employee extends person
{
}
public class result extends student
{
}
Instructor: Tanzila Kehkashan
3
4. GUI Components
• GUI component is an object with which the user interacts via mouse, keyboard or
another form of input, such as voice recognition.
• These are sometimes called controls or widgets (window gadgets).
• Lightweight Vs. Heavyweight GUI components
• Swing Vs. AWT components
• There are two sets of Java GUI components:
• ‘java.awt’ package (Abstract Window Toolkit)
• ‘javax.swing’ package
Instructor: Tanzila Kehkashan
4