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 Java is a concept, by which, we can perform a single action by different ways. Polymorphism is derived from two Greek words, which are:
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