What is Verification in Java?

  • Duke, the Java Mascot, in the waving pose. Duk...

    Duke-Java Mascot

    Verification of byte code is a step performed by the JVM before it runs any class file to ensure that the class file is structurally and conceptually correct as per the JVM specification.

  • If the class file fails this check, it is rejected and the JVM shuts down, indicating either security or integrity violation of the class file.
  • This verification is done by all JVMs.

Method Overshadowing in Java

Method Overshadowing is another name given to method overriding.

In Inheritance when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass.

 Here the method in the subclass is overshadowing 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.

If we want to explicitly call the method defined in the superclass then we can use the super keyword.

super.method_name  i.e the method we want to call of superclass.

Method Overriding in Java

  • When a method in a subclass has the same name and type 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. The version of the method defined by the superclass will be hidden.
  •  Method overriding occurs only when the names and the type signatures of the two methods are identical. If they are not, then the two methods are simply overloaded.
Why Use Method Overriding?

Overridden methods allow Java to support run-time polymorphism.

Polymorphism is essential to object-oriented programming for one reason:

it allows a general class to specify methods that will be common to all of its derivatives, while allowing subclasses to define the specific implementation of some or all of those methods. Overridden methods are another way that Java implements the “one interface, multiple methods” aspect of polymorphism.

 

Super keyword in Java- Java Key Points

In Java super keyword has two main uses

1)The first calls the superclass’ constructor.

2)The second is used to access a member of the superclass that has been hidden by a member of a subclass.

1)The first calls the superclass’ constructor.

super( ) must always be the first statement executed inside a subclass’ constructor.

When a subclass calls super( ), it is calling the constructor of its immediate superclass.

2)The second is used to access a member of the superclass that has been hidden by a member of a subclass.

This second form of super is most applicable to situations in which member names of a subclass hide members by the same name in the superclass.