java程式設計如下:
public class animal {
int age;
String name;
public void setAge(int age){
this.age = age;
}
public void setName(String name){
this.name = name;
public int getAge(){
return age;
public String getName(){
return name;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
animal an = new animal();
an.setAge(10);
an.setName("mimi");
System.out.println("該動物是"+an.getName()+","+"年齡為"+an.getAge());
java程式設計如下:
public class animal {
int age;
String name;
public void setAge(int age){
this.age = age;
}
public void setName(String name){
this.name = name;
}
public int getAge(){
return age;
}
public String getName(){
return name;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
animal an = new animal();
an.setAge(10);
an.setName("mimi");
System.out.println("該動物是"+an.getName()+","+"年齡為"+an.getAge());
}
}