SlideShare a Scribd company logo
1 of 7
Download to read offline
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

What's hot

Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Nuzhat Memon
 
البرمجة الهدفية بلغة جافا - الوراثة
البرمجة الهدفية بلغة جافا - الوراثةالبرمجة الهدفية بلغة جافا - الوراثة
البرمجة الهدفية بلغة جافا - الوراثةMahmoud Alfarra
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in JavaJava2Blog
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In JavaSpotle.ai
 
Polymorphism
PolymorphismPolymorphism
PolymorphismKumar
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in javasureshraj43
 
P.7 media 2 polymorphism
P.7 media 2 polymorphismP.7 media 2 polymorphism
P.7 media 2 polymorphismahmadmuzaqqi
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java Janu Jahnavi
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Pritom Chaki
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructorsJan Niño Acierto
 

What's hot (20)

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

Similar to Learn java lessons_online

Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Geekster
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptxthamaraiselvangts441
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
Unit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfUnit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfArpana Awasthi
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsVinay Kumar
 
Lecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationLecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationbhargavi804095
 
Lecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionLecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionbhargavi804095
 
Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.docJoyce Thomas
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdfvenud11
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptxSajidTk2
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.pptParikhitGhosh1
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and PolymorphismKartikKapgate
 

Similar to Learn java lessons_online (20)

Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
Unit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfUnit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdf
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 
Lecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationLecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentation
 
Lecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionLecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaion
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.doc
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
 
Selenium Training .pptx
Selenium Training .pptxSelenium Training .pptx
Selenium Training .pptx
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Ch5 inheritance
Ch5 inheritanceCh5 inheritance
Ch5 inheritance
 
11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf
 

More from nishajj

Career guidance: tips for job seekers during holidays
Career guidance: tips for job seekers during holidaysCareer guidance: tips for job seekers during holidays
Career guidance: tips for job seekers during holidaysnishajj
 
Monday motivation: tips to keep you motivated throughout the week
Monday motivation: tips to keep you motivated throughout the weekMonday motivation: tips to keep you motivated throughout the week
Monday motivation: tips to keep you motivated throughout the weeknishajj
 
Why internship is necessary for getting a job
Why internship is necessary for getting a jobWhy internship is necessary for getting a job
Why internship is necessary for getting a jobnishajj
 
Career guidance tips on how to write a cv
Career guidance tips on how to write a cvCareer guidance tips on how to write a cv
Career guidance tips on how to write a cvnishajj
 
Career advice on how to build respect at workplace
Career advice on how to build respect at workplaceCareer advice on how to build respect at workplace
Career advice on how to build respect at workplacenishajj
 
Career advice:the job search mistakes to avoid
Career advice:the job search mistakes to avoidCareer advice:the job search mistakes to avoid
Career advice:the job search mistakes to avoidnishajj
 
Career advice: how to get more job interviews
Career advice: how to get more job interviewsCareer advice: how to get more job interviews
Career advice: how to get more job interviewsnishajj
 
How to use linked in to find job opportunities
How to use linked in to find job opportunitiesHow to use linked in to find job opportunities
How to use linked in to find job opportunitiesnishajj
 
All in one place for job seekers
All in one place for job seekersAll in one place for job seekers
All in one place for job seekersnishajj
 
Career guidance tips on how to become an ifs officer
Career guidance tips on how to become an ifs officerCareer guidance tips on how to become an ifs officer
Career guidance tips on how to become an ifs officernishajj
 
Important tips: preparation for campus placement
Important tips: preparation for campus placementImportant tips: preparation for campus placement
Important tips: preparation for campus placementnishajj
 
Most frequently asked infosys technical interview questions and answers in 2018
Most frequently asked infosys technical interview questions and answers in 2018Most frequently asked infosys technical interview questions and answers in 2018
Most frequently asked infosys technical interview questions and answers in 2018nishajj
 
Frequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersFrequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersnishajj
 
Frequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersFrequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersnishajj
 
Preparation tips: how to crack aptitude test
Preparation tips: how to crack aptitude testPreparation tips: how to crack aptitude test
Preparation tips: how to crack aptitude testnishajj
 
How to prepare jee 2018
How to prepare jee 2018How to prepare jee 2018
How to prepare jee 2018nishajj
 
Career and scope in hotel management
Career and scope in hotel managementCareer and scope in hotel management
Career and scope in hotel managementnishajj
 
Career advice on how to answer “why did you leave your last job”
Career advice on how to answer “why did you leave your last job”Career advice on how to answer “why did you leave your last job”
Career advice on how to answer “why did you leave your last job”nishajj
 
Top entrance exams: explore career options after 12th
Top entrance exams: explore career options after 12thTop entrance exams: explore career options after 12th
Top entrance exams: explore career options after 12thnishajj
 
Resume tips:how to highlight job skills and standout amidst others
Resume tips:how to highlight job skills and standout amidst othersResume tips:how to highlight job skills and standout amidst others
Resume tips:how to highlight job skills and standout amidst othersnishajj
 

More from nishajj (20)

Career guidance: tips for job seekers during holidays
Career guidance: tips for job seekers during holidaysCareer guidance: tips for job seekers during holidays
Career guidance: tips for job seekers during holidays
 
Monday motivation: tips to keep you motivated throughout the week
Monday motivation: tips to keep you motivated throughout the weekMonday motivation: tips to keep you motivated throughout the week
Monday motivation: tips to keep you motivated throughout the week
 
Why internship is necessary for getting a job
Why internship is necessary for getting a jobWhy internship is necessary for getting a job
Why internship is necessary for getting a job
 
Career guidance tips on how to write a cv
Career guidance tips on how to write a cvCareer guidance tips on how to write a cv
Career guidance tips on how to write a cv
 
Career advice on how to build respect at workplace
Career advice on how to build respect at workplaceCareer advice on how to build respect at workplace
Career advice on how to build respect at workplace
 
Career advice:the job search mistakes to avoid
Career advice:the job search mistakes to avoidCareer advice:the job search mistakes to avoid
Career advice:the job search mistakes to avoid
 
Career advice: how to get more job interviews
Career advice: how to get more job interviewsCareer advice: how to get more job interviews
Career advice: how to get more job interviews
 
How to use linked in to find job opportunities
How to use linked in to find job opportunitiesHow to use linked in to find job opportunities
How to use linked in to find job opportunities
 
All in one place for job seekers
All in one place for job seekersAll in one place for job seekers
All in one place for job seekers
 
Career guidance tips on how to become an ifs officer
Career guidance tips on how to become an ifs officerCareer guidance tips on how to become an ifs officer
Career guidance tips on how to become an ifs officer
 
Important tips: preparation for campus placement
Important tips: preparation for campus placementImportant tips: preparation for campus placement
Important tips: preparation for campus placement
 
Most frequently asked infosys technical interview questions and answers in 2018
Most frequently asked infosys technical interview questions and answers in 2018Most frequently asked infosys technical interview questions and answers in 2018
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 answersFrequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answers
 
Frequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answersFrequently asked tcs technical interview questions and answers
Frequently asked tcs technical interview questions and answers
 
Preparation tips: how to crack aptitude test
Preparation tips: how to crack aptitude testPreparation tips: how to crack aptitude test
Preparation tips: how to crack aptitude test
 
How to prepare jee 2018
How to prepare jee 2018How to prepare jee 2018
How to prepare jee 2018
 
Career and scope in hotel management
Career and scope in hotel managementCareer and scope in hotel management
Career and scope in hotel management
 
Career advice on how to answer “why did you leave your last job”
Career advice on how to answer “why did you leave your last job”Career advice on how to answer “why did you leave your last job”
Career advice on how to answer “why did you leave your last job”
 
Top entrance exams: explore career options after 12th
Top entrance exams: explore career options after 12thTop entrance exams: explore career options after 12th
Top entrance exams: explore career options after 12th
 
Resume tips:how to highlight job skills and standout amidst others
Resume tips:how to highlight job skills and standout amidst othersResume tips:how to highlight job skills and standout amidst others
Resume tips:how to highlight job skills and standout amidst others
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Recently uploaded (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

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