?? shapeinterfacetest.java
字號:
package sample;
public class ShapeInterfaceTest {
public static void main(String[] args) {
Shape circle1=new Circle(2.0,3.0,5.0);
Shape rectangle1=new Rectangle(3.4,6.8,433,6567);
circle1.draw();
rectangle1.draw();
}
}
interface Shape
{
public abstract void draw();
//{
//System.out.println("draw in shape");
//}
}
class Circle implements Shape
{
private double x;
private double y;
private double r;
Circle()
{
r=1.0;
}
Circle(double nr)
{
r=nr;
}
Circle(double x, double y,double r)
{
this.x = x;
this.y = y;
this.r = r;
}
public void draw()
{
System.out.println("draw in circle");
System.out.println("x: " + x + "\n" + "y :" + y + "\n" + "r: " + r);
}
}
class Rectangle implements Shape
{
private double x;
private double y;
private double height;
private double width;
Rectangle()
{
height=1.0;
width=1.0;
}
Rectangle(double nheight,double nwidth)
{
height=nheight;
width=nwidth;
}
Rectangle(double nx,double ny,double nheight,double nwidth)
{
this.x = nx;
this.y = ny;
height=nheight;
width=nwidth;
}
public void draw()
{
System.out.println("draw in rectangle");
System.out.println("x: " + x + "\n" + "y :" + y + "\n" +
"height: " + height + "\n" + "weight: " + width);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -