dynamic polymorphism
Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle,
Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate
dynamic polymorphism.?
View Answers
July 21, 2011 at 12:49 PM
class point{
void show(){
System.out.println("This is the Point Base class");
}
}
class shape extends point{
void display(){
System.out.println("Different shapes can be developed with different number of points");
}
}
class rectangle extends shape{
int l,b;
void getdata(int x,int y){
l=x;b=y;
}
void area(){
System.out.println("Length:"+l);
System.out.println("Breadth:"+b);
System.out.println("Area:"+(l*b));
}
}
class square extends shape{
int a;
void gdata(int x){
a=x;
}
void area(){
System.out.println("Side:"+a);
System.out.println("Area:"+(a*a));
}
}
class circle extends shape{
int r;
void get(int x){
r=x;
}
void area(){
System.out.println("Radius:"+r);
System.out.println("Area:"+(3.14*r*r));
}
}
class triangle extends shape{
int b,h;
void tdata(int x,int y){
b=x;h=y;
}
void area(){
System.out.println("Base:"+b);
System.out.println("Height:"+h);
System.out.println("Area:"+(0.5*b*h));
}
}
class ShapeTest{
public static void main(String args[]){
rectangle r = new rectangle();
square s = new square();
circle c = new circle();
triangle t = new triangle();
r.show();
s.display();
System.out.println("");
System.out.println("Rectangle:");
System.out.println();
r.getdata(12,6);
r.area();
System.out.println("");
System.out.println("Square:");
System.out.println();
s.gdata(7);
s.area();
System.out.println("");
System.out.println("Circle:");
System.out.println();
c.get(5);
c.area();
System.out.println("");
System.out.println("Triangle:");
System.out.println();
t.tdata(4,7);
t.area();
}
}
Ads
Related Tutorials/Questions & Answers:
dynamic polymorphism
dynamic polymorphism Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle,
Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate
dynamic polymorphism
dynamic polymorphism
dynamic polymorphism give an example for
dynamic polymorphism?
Dynamic polymorphism is where a class overrides a superclass method... of
Dynamic Polymorphism that will
develop suitable hierarchy, classes for Point, Shape
Advertisements
polymorphism
polymorphism can we achieve without overriding
polymorphism
What is Polymorphism in Java?
Polymorphism in Java means a subclass, though having its own unique behavior... IS-A relationship is polymorphic. In
Polymorphism, common interface is used while writing code. Single
polymorphism is achieved by method overriding while multiple
Polymorphism
;
OOPs revolve around the four concepts:
1. Encapsulation
2.
Polymorphism..., programmatically.
Here we will discuss
Polymorphism briefly:
--
Polymorphism... behavior to method calls of the same name.
--
Polymorphism does not allow
dynamic textfields
dynamic textfields Hi,
I am a fresher and joined recently in one company. they gave me a desktop application project using swings.here is my detailed spec Screen 1 - The user enters the ingredients from a food product, saves
Dynamic form
Dynamic form I need to make a
dynamic form using jsp for example, i will need a list of items which when we select one option another list is modified ( like 2 lists of countries and citys ), and also a radio button wich once
dynamic form
dynamic form I need to make a
dynamic form using php, for example, i will need a list of items which when we select one option another list is modified ( like 2 lists of countries and citys from a dtabase ), and also a radio
dynamic query
dynamic query DECLARE
QUERY VARCHAR2(32767);
FIN_QUERY VARCHAR2(32767);
CURSOR C IS
(select distinct PORTFOLIO from MPE_TEST1);
CURSOR C2 IS
SELECT DISTINCT PORTFOLIO_LEVEL, PORTFOLIO FROM MPE_TEST1 ORDER
ModuleNotFoundError: No module named 'dynamic'
ModuleNotFoundError: No module named '
dynamic' Hi,
My Python... '
dynamic'
How to remove the ModuleNotFoundError: No module named '
dynamic... to install padas library.
You can install
dynamic python with following command
ModuleNotFoundError: No module named 'dynamic'
ModuleNotFoundError: No module named '
dynamic' Hi,
My Python... '
dynamic'
How to remove the ModuleNotFoundError: No module named '
dynamic... to install padas library.
You can install
dynamic python with following command
Dynamic Array iPhone
Dynamic Array iPhone
Dynamic Array iPhone
How can i add NSMutable array dynamically into my iPhone App
Dynamic html examples
Dynamic html examples Hi,
What is
Dynamic HTML? Explain with
dynamic html examples.
Thanks
Hi,
DHTML stands for
Dynamic HTML and is uses the HTML, JavaScript, DOM, & CSS in a program.
Following is very simple