Compile Time Polymorphism
Compile Time Polymorphism
runtime polymorphism:
by using method overriding we can achieve runtime polymorphism
an ability of method to take many forms
runtime polymorphism is also called as dynamic binding
early binding:
1.incase of method overloading when we call the overloaded method then the decision
about method binding taken by the compiler based up on parameters and orguments
so hence it will perform in the compile time so hence it is called compile time
polymorphism
dynamic binding:
in case of upcasting when we call the overloaded method then the method binding
taken by the jvm based on the object
method binding:
the process of attaching the implimentation to its method call
1.implicit casting
2.explicit casting
upcasting :process of providing subclass object to the super class reference i.e
subclass object super class reference
downcasting: process of refering to the object back to the subclass
in case of downcasting syntactically correct but logically wrong then we can get
the exception called class cost execption
to avoid this exeception we have use the instanceOf() keyword
charectoristics of upcasting:
1.incase of upcasting by using parent class reference can access the inherited
properties and behaviours but not subclass specific variables and methods
2.incase of upcasting by using parent class reference if we invoke the overridden
method then it will executes the implementation from subclass
2.abstract methods:
1.the method which is having only declaration but not implementation is called
abstract method
2.abstract method is always declared with the abstract keyword
3.abstract method should be terminated with semicolon(;);
4.abstract method can be declared inside only abstract method and interface but not
inside normal class
abstract class abstract method and interfaces are used to achieve the abstraction
accessmodifiers:
it will give the access visibility to the java members
1.public :
it is the heist visibility access modifier in java
all the java members can be public
public members can be access inside the class outside the class inside the package
outside the package
2.protected:
protected members can be access inside the class out side the class inside the
package outside the package
if we have to access protected members outside the package we have to perform
inheritance
outer class cannot be protected
3.default:
it is an automatic access modifier i.e if user don't provide any modifier then by
default it takes default
we don't provide default explicitly
outer class can be default
default is a package level modifier
default members can access inside the class out side the class inside the package
but not outside the package
4.private:
it is class level modifier
outer class can not be private
private members can not be access outside the class