返回列表 發帖
  1. public class Main {

  2.         public static void main(String[] args) {
  3.                 // TODO 自動產生的方法 Stub
  4.      dog dog =new dog();
  5.            dog.name="球球";
  6.          dog dog1=new dog();
  7.          dog1.name="憨憨";
  8.          System.out.println(dog.name);
  9.          System.out.println(dog1.name);
  10.         }

  11. }
複製代碼
  1. public class dog {
  2.    static String name;
  3.    int age;
  4.    double weight;
  5.    String color;
  6.    
  7.    public void ShowProfile()
  8.    {
  9.            System.out.println(String.format("%s今年%d歲,體重%f公斤毛色%s",this.name,this.age,this.weight,this.color));
  10.    }
  11.    public void makesound(int n)
  12.    {
  13.            for(int i=0;i<n;i++)
  14.            {
  15.                    System.out.print("汪~");
  16.            }
  17.            System.out.println();
  18.    }
  19.    dog()
  20.    {
  21.           
  22.    }
  23.    dog(String name,int age,double weight,String color)
  24.    {
  25.          this.name=name;
  26.          this.age=age;
  27.          this.weight=weight;
  28.          this.color=color;
  29.    }
  30.    
  31. }
複製代碼

TOP

返回列表