SlideShare a Scribd company logo
Learn Java lessons online
Java is a high-level programming language developed by Sun Microsystems but
later was taken over by Oracle. This tutorial gives a basic understanding on
Polymorphism.
What is Polymorphism?
The ability of an object to take many forms is Polymorphism. The most common
use of polymorphism in OOP occurs when a parent class reference is used to
mention to a child class object. Any Java object that can pass more than one IS-A
test is considered to be polymorphic.
Polymorphism is the capability of a method to do variety of things based on the
object that it is acting upon. In simple words, polymorphism allows you to define
one interface and have multiple executions.
Key points:
•This feature allows one interface to be used for many class of actions.
•An operation may show different behavior in different instances.
•Types of data used in the operation decide the behavior
•Polymorphism is extensively used in executing inheritance.
Two types of polymorphism available in JAVA are:
1) Method Overloading
2) Method Overriding
A method is a set of code which is mentioned by name and can be invoked at any
point in a program simply by utilizing the method’s name.
1)Method Overloading:
With different argument list or parameters,in Java it is possible to define two or
more methods of same name in a class. This concept is called Method
Overloading. An overloaded method can throw different expectations. And it can
have different access modifiers.
Rules for Method Overloading
Change method signature.
Return type method is never part of method signature, so only changing the
return type of method does not amount to method overloading.
Overloaded method throws the same supposition, a different exception or it
simply does not toss any exception; no effect at all on method loading.
Example:
class Overload
{
void demo (int a)
{
System.out.println ("a: " + a);
}
void demo (int a, int b)
{
System.out.println ("a and b: "
+ a + "," + b);
}
double demo(double a) {
System.out.println("double a: "
+ a);
return a*a;
}
}
class MethodOverloading
{
public static void main (String args [])
{
Overload Obj = new Overload();
double result;
Obj .demo(10);
Obj .demo(10, 20);
result = Obj .demo(5.5);
System.out.println("O/P : " +
result);
}
}
Here the method demo() is encumbered 3 times: first having 1 int parameter, second
one has 2 int parameters and third one is having double arg. The methods are
implored with the same type and number of variable used.
Output:
a: 10
a and b: 10,20
double a: 5.5
O/P : 30.25
2) Method Overriding
In method overriding, child class overrides the parent class method without even
touching the source code of the base class. Child class has the same method as of
base class.
Rules for Method Overriding:
1.Only inherited methods can be overridden
2.object type determines which overridden method will be used at execution.
3.Overriding method can have different result type
4.Abstract methods must be overridden
5.What can’t be overridden are constructors and static and final methods.
6.It is also known as Runtime polymorphism.
class
Vehicle {
public void move () {
System.out.println ("Vehicles are
used for moving from one place to another ");
}
}
class Car extends Vehicle {
public void move () {
super. move (); // invokes the super class
method
System.out.println ("Car is a good
medium of transport ");
}
}
public class TestCar {
public static void main (String args []){
Vehicle b = new Car (); // Vehicle
reference but Car object
b.move (); //Calls the method in Car
class
}
}
Output:
In order to commute from one place to another
vehicles are used.
Car is a good
medium of transportation
Read More :14 Reasons that Java Script is Different from Java

More Related Content

PPT
Introduction to method overloading & method overriding in java hdm
PPTX
What is method overloading and overriding in java?
PDF
Method Overloading In Java
PPT
Polymorphism in java, method overloading and method overriding
PPTX
Polymorphism in java
PPTX
encapsulation, inheritance, overriding, overloading
PPTX
Overloading and overriding in vb.net
Introduction to method overloading & method overriding in java hdm
What is method overloading and overriding in java?
Method Overloading In Java
Polymorphism in java, method overloading and method overriding
Polymorphism in java
encapsulation, inheritance, overriding, overloading
Overloading and overriding in vb.net

What's hot (20)

PDF
Polymorphism in oop
PPTX
Std 12 computer chapter 8 classes and object in java (part 2)
PPTX
Java(Polymorphism)
PPT
البرمجة الهدفية بلغة جافا - الوراثة
PPTX
Basic concept of class, method , command line-argument
PDF
Polymorphism in Java
PPT
Oops in Java
PDF
Javapolymorphism
PDF
Polymorphism In Java
PPT
Polymorphism
PPTX
Polymorphism in java
PDF
Polymorphism
PPTX
P.7 media 2 polymorphism
PPT
Method overloading
PPTX
Ppt on this and super keyword
PPTX
Polymorphism in java
PPT
Polymorphism in java
PPTX
Object Orinted Programing(OOP) concepts \
PPT
Java lec class, objects and constructors
Polymorphism in oop
Std 12 computer chapter 8 classes and object in java (part 2)
Java(Polymorphism)
البرمجة الهدفية بلغة جافا - الوراثة
Basic concept of class, method , command line-argument
Polymorphism in Java
Oops in Java
Javapolymorphism
Polymorphism In Java
Polymorphism
Polymorphism in java
Polymorphism
P.7 media 2 polymorphism
Method overloading
Ppt on this and super keyword
Polymorphism in java
Polymorphism in java
Object Orinted Programing(OOP) concepts \
Java lec class, objects and constructors
Ad

Similar to Learn java lessons_online (20)

PPTX
Oop concepts classes Method Overriding.pptx
PDF
Java Polymorphism: Types And Examples (Geekster)
PPTX
polymorphism method overloading and overriding .pptx
PPTX
Chapter 04 Object Oriented programming .pptx
PPTX
Java interview questions 1
PDF
Method overloading and method overriding
PDF
Unit 2 Part 1 POLYMORPHISM.pdf
DOC
Core java interview questions
PPTX
Polymorphism.pptx
PPTX
Lecture5_Method_overloading_Final power point presentation
PPTX
Lecture4_Method_overloading power point presentaion
PPTX
Basics to java programming and concepts of java
PPTX
Lecture_5_Method_overloading_Final.pptx in Java
DOCX
Core java by amit
DOCX
Corejavainterviewquestions.doc
PDF
1669617800196.pdf
PPTX
OOP- PolymorphismFinal12injavait101.pptx
PPTX
Selenium Training .pptx
PPT
InheritanceAndPolymorphismprein Java.ppt
PPT
06 InheritanceAndPolymorphism.ppt
Oop concepts classes Method Overriding.pptx
Java Polymorphism: Types And Examples (Geekster)
polymorphism method overloading and overriding .pptx
Chapter 04 Object Oriented programming .pptx
Java interview questions 1
Method overloading and method overriding
Unit 2 Part 1 POLYMORPHISM.pdf
Core java interview questions
Polymorphism.pptx
Lecture5_Method_overloading_Final power point presentation
Lecture4_Method_overloading power point presentaion
Basics to java programming and concepts of java
Lecture_5_Method_overloading_Final.pptx in Java
Core java by amit
Corejavainterviewquestions.doc
1669617800196.pdf
OOP- PolymorphismFinal12injavait101.pptx
Selenium Training .pptx
InheritanceAndPolymorphismprein Java.ppt
06 InheritanceAndPolymorphism.ppt
Ad

More from nishajj (20)

PPT
Career guidance: tips for job seekers during holidays
PPT
Monday motivation: tips to keep you motivated throughout the week
PDF
Why internship is necessary for getting a job
PPT
Career guidance tips on how to write a cv
PDF
Career advice on how to build respect at workplace
PPT
Career advice:the job search mistakes to avoid
PPT
Career advice: how to get more job interviews
PPTX
How to use linked in to find job opportunities
PPTX
All in one place for job seekers
PPT
Career guidance tips on how to become an ifs officer
PPT
Important tips: preparation for campus placement
PPT
Most frequently asked infosys technical interview questions and answers in 2018
PPT
Frequently asked tcs technical interview questions and answers
PDF
Frequently asked tcs technical interview questions and answers
PPT
Preparation tips: how to crack aptitude test
PPT
How to prepare jee 2018
PPT
Career and scope in hotel management
PDF
Career advice on how to answer “why did you leave your last job”
PPT
Top entrance exams: explore career options after 12th
PPT
Resume tips:how to highlight job skills and standout amidst others
Career guidance: tips for job seekers during holidays
Monday motivation: tips to keep you motivated throughout the week
Why internship is necessary for getting a job
Career guidance tips on how to write a cv
Career advice on how to build respect at workplace
Career advice:the job search mistakes to avoid
Career advice: how to get more job interviews
How to use linked in to find job opportunities
All in one place for job seekers
Career guidance tips on how to become an ifs officer
Important tips: preparation for campus placement
Most frequently asked infosys technical interview questions and answers in 2018
Frequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answers
Preparation tips: how to crack aptitude test
How to prepare jee 2018
Career and scope in hotel management
Career advice on how to answer “why did you leave your last job”
Top entrance exams: explore career options after 12th
Resume tips:how to highlight job skills and standout amidst others

Recently uploaded (20)

PPTX
master seminar digital applications in india
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Classroom Observation Tools for Teachers
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Institutional Correction lecture only . . .
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Insiders guide to clinical Medicine.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
master seminar digital applications in india
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Classroom Observation Tools for Teachers
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Institutional Correction lecture only . . .
O7-L3 Supply Chain Operations - ICLT Program
PPH.pptx obstetrics and gynecology in nursing
STATICS OF THE RIGID BODIES Hibbelers.pdf
VCE English Exam - Section C Student Revision Booklet
102 student loan defaulters named and shamed – Is someone you know on the list?
Insiders guide to clinical Medicine.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Types and Its function , kingdom of life
human mycosis Human fungal infections are called human mycosis..pptx
Computing-Curriculum for Schools in Ghana
01-Introduction-to-Information-Management.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
2.FourierTransform-ShortQuestionswithAnswers.pdf

Learn java lessons_online

  • 1. Learn Java lessons online Java is a high-level programming language developed by Sun Microsystems but later was taken over by Oracle. This tutorial gives a basic understanding on Polymorphism. What is Polymorphism? The ability of an object to take many forms is Polymorphism. The most common use of polymorphism in OOP occurs when a parent class reference is used to mention to a child class object. Any Java object that can pass more than one IS-A test is considered to be polymorphic. Polymorphism is the capability of a method to do variety of things based on the object that it is acting upon. In simple words, polymorphism allows you to define one interface and have multiple executions. Key points: •This feature allows one interface to be used for many class of actions. •An operation may show different behavior in different instances. •Types of data used in the operation decide the behavior •Polymorphism is extensively used in executing inheritance. Two types of polymorphism available in JAVA are: 1) Method Overloading
  • 2. 2) Method Overriding A method is a set of code which is mentioned by name and can be invoked at any point in a program simply by utilizing the method’s name. 1)Method Overloading: With different argument list or parameters,in Java it is possible to define two or more methods of same name in a class. This concept is called Method Overloading. An overloaded method can throw different expectations. And it can have different access modifiers. Rules for Method Overloading Change method signature. Return type method is never part of method signature, so only changing the return type of method does not amount to method overloading. Overloaded method throws the same supposition, a different exception or it simply does not toss any exception; no effect at all on method loading. Example: class Overload { void demo (int a) { System.out.println ("a: " + a);
  • 3. } void demo (int a, int b) { System.out.println ("a and b: " + a + "," + b); } double demo(double a) { System.out.println("double a: " + a); return a*a; } } class MethodOverloading { public static void main (String args [])
  • 4. { Overload Obj = new Overload(); double result; Obj .demo(10); Obj .demo(10, 20); result = Obj .demo(5.5); System.out.println("O/P : " + result); } } Here the method demo() is encumbered 3 times: first having 1 int parameter, second one has 2 int parameters and third one is having double arg. The methods are implored with the same type and number of variable used. Output: a: 10 a and b: 10,20 double a: 5.5
  • 5. O/P : 30.25 2) Method Overriding In method overriding, child class overrides the parent class method without even touching the source code of the base class. Child class has the same method as of base class. Rules for Method Overriding: 1.Only inherited methods can be overridden 2.object type determines which overridden method will be used at execution. 3.Overriding method can have different result type 4.Abstract methods must be overridden 5.What can’t be overridden are constructors and static and final methods. 6.It is also known as Runtime polymorphism. class Vehicle { public void move () { System.out.println ("Vehicles are used for moving from one place to another ");
  • 6. } } class Car extends Vehicle { public void move () { super. move (); // invokes the super class method System.out.println ("Car is a good medium of transport "); } } public class TestCar { public static void main (String args []){ Vehicle b = new Car (); // Vehicle reference but Car object
  • 7. b.move (); //Calls the method in Car class } } Output: In order to commute from one place to another vehicles are used. Car is a good medium of transportation Read More :14 Reasons that Java Script is Different from Java