package artistdemo;
class Shape {
void drow() {
System.out.println("Drawing a Shape.");
}
}
class Rectangle extends Shape {
int width,height;
Rectangle(int w,int h) {
width = w;
height = h;
}
void drow() {
System.out.println("Draw a rectangle...width="+width+"height="+height);
}
}
class Triangle extends Shape {
int base,height;
Triangle(int b,int h){
base = b;
height = h;
}
void drow() {
System.out.println("Draw a Triangle...base="+base+"height="+height);
}
}
class Artist {
public void drawShape(Shape s){
s.drow();
}
}
public class ArtistDemo {
public static void main(String[] args) {
Shape a = new Shape();
Rectangle b = new Rectangle(3,4);
Triangle c = new Triangle(6,7);
Artist x = new Artist();
x.drawShape(a);
x.drawShape(b);
x.drawShape(c);
}
} |
package artistdemo;
class Shape {
void drow() {
System.out.println("Drawing a Shape.");
}
}
class Rectangle extends Shape {
int width,height;
Rectangle(int w,int h) {
width = w;
height = h;
}
void drow() {
System.out.println("Draw a rectangle...width="+width+"height="+height);
}
}
class Triangle extends Shape {
int base,height;
Triangle(int b,int h){
base = b;
height = h;
}
void drow() {
System.out.println("Draw a Triangle...base="+base+"height="+height);
}
}
class Artist {
public void drawShape(Shape s){
s.drow();
}
}
public class ArtistDemo {
public static void main(String[] args) {
Shape a = new Shape();
Rectangle b = new Rectangle(3,4);
Triangle c = new Triangle(6,7);
Artist x = new Artist();
x.drawShape(a);
x.drawShape(b);
x.drawShape(c);
}
}