Introduction
Software Requirement
Polymorphism
- 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

Join the conversation! Your thoughts help the community grow.