- public class ch78
- {
- public static void main(String args[])
- {
- Ball b1=new Ball(18.4,"red ball");
- System.out.println("名稱: "+b1.getName());
- System.out.println("半徑: "+b1.getRadius());
- }
- }
- class Ball
- {
- double radius;
- String name;
- public Ball(double radius, String name)
- {
- this.radius=radius;
- this.name=name;
- }
- public double getRadius()
- {
- return radius;
- }
- public String getName()
- {
- return name;
- }
- }
複製代碼 |