Java Articles - Page 682 of 745

Runtime Polymorphism in Java

Priya Pallavi
Updated on 17-Jun-2020 07:28:06

18K+ Views

Method overriding is an example of runtime polymorphism. In method overriding, a subclass overrides a method with the same signature as that of in its superclass. During compile time, the check is made on the reference type. However, in the runtime, JVM figures out the object type and would run the method that belongs to that particular object.ExampleSee the example below to understand the concept − Live Democlass Animal {    public void move() {       System.out.println("Animals can move");    } } class Dog extends Animal {    public void move() {       System.out.println("Dogs can walk and ... Read More

Runtime Polymorphism in Java

Priya Pallavi
Updated on 17-Jun-2020 07:28:06

18K+ Views

Method overriding is an example of runtime polymorphism. In method overriding, a subclass overrides a method with the same signature as that of in its superclass. During compile time, the check is made on the reference type. However, in the runtime, JVM figures out the object type and would run the method that belongs to that particular object.ExampleSee the example below to understand the concept − Live Democlass Animal {    public void move() {       System.out.println("Animals can move");    } } class Dog extends Animal {    public void move() {       System.out.println("Dogs can walk and ... Read More

Can we inherit a final method in Java?

Shriansh Kumar
Updated on 16-Apr-2025 19:07:50

968 Views

In Java, we cannot override a final method. Once a method is declared final, the Java compiler marks this method as non changeable. Therefore, behaviour of the final method will be the same throughout the application. Suppose you are building an payment application. There is a method that calculates transaction fees based on the amount. You must declare this method as final to make sure each subclass use the same calculation logic. What is a final Method in Java? A method declared using the final keyword, is called as final method. The final keyword is a non-access modifier and used ... Read More

Can we inherit a final method in Java?

Shriansh Kumar
Updated on 16-Apr-2025 19:07:50

968 Views

In Java, we cannot override a final method. Once a method is declared final, the Java compiler marks this method as non changeable. Therefore, behaviour of the final method will be the same throughout the application. Suppose you are building an payment application. There is a method that calculates transaction fees based on the amount. You must declare this method as final to make sure each subclass use the same calculation logic. What is a final Method in Java? A method declared using the final keyword, is called as final method. The final keyword is a non-access modifier and used ... Read More

Can we inherit a final method in Java?

Shriansh Kumar
Updated on 16-Apr-2025 19:07:50

968 Views

In Java, we cannot override a final method. Once a method is declared final, the Java compiler marks this method as non changeable. Therefore, behaviour of the final method will be the same throughout the application. Suppose you are building an payment application. There is a method that calculates transaction fees based on the amount. You must declare this method as final to make sure each subclass use the same calculation logic. What is a final Method in Java? A method declared using the final keyword, is called as final method. The final keyword is a non-access modifier and used ... Read More

Can we initialize blank final variable in Java

Amit Sharma
Updated on 30-Jul-2019 22:30:21

1K+ Views

Yes! You can initialize a blank final variable in constructor or instance initialization block.

Can we initialize blank final variable in Java

Amit Sharma
Updated on 30-Jul-2019 22:30:21

1K+ Views

Yes! You can initialize a blank final variable in constructor or instance initialization block.

Can we initialize blank final variable in Java

Amit Sharma
Updated on 30-Jul-2019 22:30:21

1K+ Views

Yes! You can initialize a blank final variable in constructor or instance initialization block.

Covariant return types in Java

Shriansh Kumar
Updated on 24-Apr-2025 18:32:02

11K+ Views

In Java, covariant return types allow an overriding method to return a subtype of the supertype. Here, the return type of the parent class is called the supertype, and the return type of the child class is known as the subtype, if and only if it is a subclass of the parent class's return type. Sounds confusing, right? Well! It is not as confusing as it sounds. Read the whole article to understand this concept. Java Covariant Return Types Covariant return type refers to the return type of an overriding method. It works only for non-primitive return types, such as Classes, Arrays, ... Read More

Covariant return types in Java

Shriansh Kumar
Updated on 24-Apr-2025 18:32:02

11K+ Views

In Java, covariant return types allow an overriding method to return a subtype of the supertype. Here, the return type of the parent class is called the supertype, and the return type of the child class is known as the subtype, if and only if it is a subclass of the parent class's return type. Sounds confusing, right? Well! It is not as confusing as it sounds. Read the whole article to understand this concept. Java Covariant Return Types Covariant return type refers to the return type of an overriding method. It works only for non-primitive return types, such as Classes, Arrays, ... Read More

Advertisements