Java-Instanceof

Instanceof The instanceof is used to knowing the type of an object during run time. The instanceof operator has this general form : objref instanceof type Here, objref is a reference to an instance of a class, and type is a class type. If objref is of the specified type or can be cast into the … Read more…

Java-Final to Prevent Inheritance

Final to Prevent Inheritance A class that is declared with the final modifier cannot be extended. Sometimes we may like to prevent a class being further subclasses for security reasons. A class that cannot be subclassed is called a final class. Any attempt to inherit these classes will cause an error and the compiler will … Read more…

Java-Final to Prevent Overriding

Final to Prevent Overriding All methods and variables can be overridden by default in subclasses. If we wish to prevent the subclasses from overriding the members of the superclass, we can declare them as final using the keyword final as a modifier. If any attempt to override a final method in a subclass results in … Read more…

Java-Abstract Classes

Abstract Classes A class for which cannot create objects is called an abstract class. An abstract class is to be extended and then instantiated. Some of the methods in an abstract class may be declared as abstract methods. Such an abstract method consists of a declaration without any body, as shown below: All abstract methods … Read more…

Java-Runtime Polymorphism or Dynamic Method Dispatch

Runtime Polymorphism or Dynamic Method Dispatch Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at run time. A superclass reference variable can refer to a subclass object. Java uses this fact to resolve calls to overridden methods at run time. Here is how. When an overridden method … Read more…

Java-Multilevel Inheritance

Multilevel Inheritance Java supports multilevel hierarchy, it means that, you can build hierarchies that contain as many layers of inheritance as you want. For example, given three class called DataV1,  DataV2 and  DataV3. The class DataV1 serves as a base class for the derived class DataV2 as which in turn serves as a base class for the … Read more…