🔴🔥Run Time Polymorphism || Rules for Exception handling with Method Overriding in Java ||throws

preview_player
Показать описание
Runtime polymorphism or Dynamic Method Dispatch or dynamic binding or late binding or Method overriding

Definition : Declaring a method in sub class which is already present in parent class is known as method overriding.

Inheritance(IS-A) :- one class acquires the properties of another class

Rules for Exception handling with Method Overriding in Java

1.If parent-class method doesn’t declare any exception

Then child-class overriding-method can declare any type of unchecked exception(this is the only possibility)

If child-class overriding-method declares checked-exception, then compiler throws compile-time error

2. If parent-class method declares unchecked–exception

Then child-class overriding-method can declare no exception in the overriding-method of child-class

Then child-class overriding-method can declare any type of unchecked exception
Not necessarily same exception as that of parent-class method
(only for unchecked exception)

If child-class overriding-method declares any checked-exception, then compiler throws compile-time

3. If parent-class method declares checked exception

Then child-class overriding-method can declare no exception in the overriding-method of child-class

Then child-class overriding-method can declare any type of unchecked exception

Then child-class overriding-method can declare same type of checked exception or one of its sub-class or no exception

4. If parent-class method declares combination of both checked & unchecked exceptions

Then child-class overriding-method can declare no exception in the overriding-method of child-class

Then child-class overriding-method can declare any type of unchecked exception

Then child-class overriding-method can declare same type of checked-exception or one of its sub-class or no exception

Tags:
The java programming language in Telugu,
java programs in Telugu Explanation,
Free java Telugu course,
Java in Telugu,
java in Telugu pdf,
java in the Telugu language,
java tutorial in Telugu,
learn java in Telugu,
java in Telugu for beginners,
Association(HAS-A) in Java,
What is Aggregation in java,
What is Composition in java,
oops,
oops example,
encapsulation,
java fundamentals,
JDK,
object-oriented,
oop concepts,
abstraction,
inheritance,
polymorphism,
class, object,
method overloading,
method overriding

Рекомендации по теме
visit shbcf.ru