- public class Main {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- dog dog =new dog();
- dog.name="球球";
- dog dog1=new dog();
- dog1.name="憨憨";
- System.out.println(dog.name);
- System.out.println(dog1.name);
- }
- }
複製代碼- public class dog {
- static String name;
- int age;
- double weight;
- String color;
-
- public void ShowProfile()
- {
- System.out.println(String.format("%s今年%d歲,體重%f公斤毛色%s",this.name,this.age,this.weight,this.color));
- }
- public void makesound(int n)
- {
- for(int i=0;i<n;i++)
- {
- System.out.print("汪~");
- }
- System.out.println();
- }
- dog()
- {
-
- }
- dog(String name,int age,double weight,String color)
- {
- this.name=name;
- this.age=age;
- this.weight=weight;
- this.color=color;
- }
-
- }
複製代碼 |