Category: Inheritance

Inheritance

What is the use of equals method in Java?

What is the use of equals method in Java?

Equals method is used when we compare two objects. Default implementation of equals method is defined in Object class. The implementation is similar to == operator. Two object references are equal only if they...

abstract class constructors

abstract class constructors

The superclass Product is abstract and has a constructor. The concrete class TimesTwo has a default constructor that just hardcodes the value 2. The concrete class TimesWhat has a constructor that allows the caller...

Abstract Classes

Abstract Classes

There are situations in which you will want to define a superclass that declares the structure of a given abstraction without providing a complete implementation of every method. For implementing this Java uses abstract...

Dynamic method dispatch

Dynamic method dispatch

Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at run time, rather than compile time. Dynamic method dispatch is important because this is how Java implements...

Using super

Using super

Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super. super can be used with methods and constructors as well. Example (use super for...

Inheritance – Member Access

Inheritance – Member Access

If any of the method or data member is declared private then that private variable or member method is not inherited to the derived class. Consider an example of this :

Inheritance Introduction

Inheritance Introduction

In the Java language, classes can be derived from other classes, thereby inheriting fields and methods from those classes. A class that is derived from another class is called a subclass (also a derived...