Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Java - Polymorphism
WhatsApp
Senthilvelan Sambamoorthy
5y
3.9
k
0
0
25
Blog
Introduction
In this blog, I will explain about the Polymorphism concept in Java. It is very simple in Java programming. The output will be displayed in the Run module.
Software Requirement
JDK1.3.
Polymorphism
Polymorphism
in J
ava
is a
concept,
by which, we can perform a single action in different ways.
Polymorphism
is derived from two Greek words, which are:
poly
- many
morphs- forms
Simple program
class
Box {
int
w, h;
void
info() {
System.out.println(
"This is a simple box"
);
System.out.println(
"width = "
+ w +
" hieght "
+ h);
}
}
class
WoddenBox
extends
Box {
void
info() {
System.out.println(
"This is a Wodden box"
);
}
}
class
SteelBox
extends
Box {
void
info() {
System.out.println(
"This is a steel box"
);
}
}
class
LargeWoddenBox
extends
WoddenBox {
void
info() {
System.out.println(
"This is a Huge Wodden box"
);
}
}
class
test5 {
public
static
void
main(String arg[]) {
Box b1 =
new
Box();
WoddenBoxwb =
new
WoddenBox();
SteelBox s1 =
new
SteelBox();
LargeWoddenBox p1 =
new
LargeWoddenBox();
b1.info();
wb.info();
s1.info();
p1.info();
}
}
Explanation
In this blog, I explained about Polymorphism concept in Java programming. The output will be displayed in the Run module.
Output
Polymrphism
Java
Up Next
Steps to Run Java Program using Command Prompt
Ebook Download
View all
Coding Principles
Read by 2.7k people
Download Now!
Learn
View all
Membership not found