0% found this document useful (0 votes)
37 views3 pages

Compile Time Polymorphism

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

Compile Time Polymorphism

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

compile time polymorphism :

by using method overloading we can achieve compile time polymorphism


method overloading is nothing but same task perform by passing different inputs
compile time is also known as early binding

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

so hence it is performed at the time of execution hence it is called runtime


polymorphism

method binding:
the process of attaching the implimentation to its method call

typecasting:convert the particular datatype in to the required datatype is called


type casing

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

note:it is not possible to chieve downcasting with out upcasting


with out inheritance can not be achieve upcasting

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

instanceOf():-it is used to check the object type


always it allows to the Boolean values true/false

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

in java methods are 2 types


1.concrete method
2.abstract method
the method having declaration and implementation is called concrete method

concrete methods can be declared inside abstract method also

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

in java we have 4 accessmodifiers


1.public
2.protected
3.default
4.private

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

You might also like