TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Java - Polymorphism
Senthilvelan Sambamoorthy
Sep 27, 2019
3.8
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, you will learn about the Polymorphism concept for Java programs.
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
Next Recommended Reading
Steps to Run Java Program using Command Prompt