Found 7442 Articles for Java

Covariant return types in Java

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

10K+ 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

10K+ 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

Exception handling with method overriding in Java.

usharani
Updated on 17-Jun-2020 07:10:18

4K+ Views

Yes, we can override a method by changing only the exception handling in java pertaining the following rule −An overriding method can throw any unchecked exceptions, regardless of whether the overridden method throws exceptions or not. However, the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.

Exception handling with method overriding in Java.

usharani
Updated on 17-Jun-2020 07:10:18

4K+ Views

Yes, we can override a method by changing only the exception handling in java pertaining the following rule −An overriding method can throw any unchecked exceptions, regardless of whether the overridden method throws exceptions or not. However, the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.

Exception handling with method overriding in Java.

usharani
Updated on 17-Jun-2020 07:10:18

4K+ Views

Yes, we can override a method by changing only the exception handling in java pertaining the following rule −An overriding method can throw any unchecked exceptions, regardless of whether the overridden method throws exceptions or not. However, the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.

method overloading and type promotion in Java

Shriansh Kumar
Updated on 21-Apr-2025 16:02:36

1K+ Views

Method overloading helps to create multiple methods with the same name to perform similar operations in different ways ( using different types of parameters). Automatic Type promotion or conversion in Java is a process in which the compiler automatically promotes a small-sized data type to a larger-sized data type. It is not possible to convert a larger size to a smaller size automatically. In method overloading, the overloaded method is called based on the arguments passed. Suppose we are calling an overloaded method, and the type of argument is not the exact match to the type defined in the method ... Read More

method overloading and type promotion in Java

Shriansh Kumar
Updated on 21-Apr-2025 16:02:36

1K+ Views

Method overloading helps to create multiple methods with the same name to perform similar operations in different ways ( using different types of parameters). Automatic Type promotion or conversion in Java is a process in which the compiler automatically promotes a small-sized data type to a larger-sized data type. It is not possible to convert a larger size to a smaller size automatically. In method overloading, the overloaded method is called based on the arguments passed. Suppose we are calling an overloaded method, and the type of argument is not the exact match to the type defined in the method ... Read More

method overloading and type promotion in Java

Shriansh Kumar
Updated on 21-Apr-2025 16:02:36

1K+ Views

Method overloading helps to create multiple methods with the same name to perform similar operations in different ways ( using different types of parameters). Automatic Type promotion or conversion in Java is a process in which the compiler automatically promotes a small-sized data type to a larger-sized data type. It is not possible to convert a larger size to a smaller size automatically. In method overloading, the overloaded method is called based on the arguments passed. Suppose we are calling an overloaded method, and the type of argument is not the exact match to the type defined in the method ... Read More

inheritance(is-a) v/s composition (has-a) relationship in Java

Giri Raju
Updated on 17-Jun-2020 07:11:07

869 Views

IS-A RelationshipIS-A is a way of saying − This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance. public class Animal { } public class Mammal extends Animal { } public class Reptile extends Animal { } public class Dog extends Mammal { }Now, if we consider the IS-A relationship, we can say −Mammal IS-A AnimalReptile IS-A AnimalDog IS-A MammalHence: Dog IS-A Animal as wellWith the use of the extends keyword, the subclasses will be able to inherit all the properties of the superclass except for the private properties of the ... Read More

inheritance(is-a) v/s composition (has-a) relationship in Java

Giri Raju
Updated on 17-Jun-2020 07:11:07

869 Views

IS-A RelationshipIS-A is a way of saying − This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance. public class Animal { } public class Mammal extends Animal { } public class Reptile extends Animal { } public class Dog extends Mammal { }Now, if we consider the IS-A relationship, we can say −Mammal IS-A AnimalReptile IS-A AnimalDog IS-A MammalHence: Dog IS-A Animal as wellWith the use of the extends keyword, the subclasses will be able to inherit all the properties of the superclass except for the private properties of the ... Read More

Advertisements