public class student {
public String name;
public String sex;
public double circle(double r) {
double data=3.14*r*r;
return data;
}
}
public class plant {
public String name;
private int age;
public static String sex;
public void showname() {
System.out.println(name);
}
public void showAge() {
System.out.println(age);
}
}
public class Animal {
String name;
int eye;
int legs;
public void eat(String food){
System.out.println(name+"这种动物的食物为:"+food);
}
public void move(String moveType) {
System.out.println(name+"这种动物移动的方法是:"+moveType);
}
}
public class Persion {
String name;
int age;
public void showName() {
System.out.println("姓名:"+name);
}
public int getAge() {
return age;
}
}
public class Hello {
public static void main(String[] args) {
Persion teacher = new Persion();
teacher.name="刘冰";
teacher.age=20;
teacher.showName();
int a=teacher.getAge();
System.out.println("年龄"+a);
Animal dog = new Animal();
dog.name="旺财";
dog.eye=2;
dog.legs=4;
dog.eat("骨头");
dog.move("跑");
plant meigui = new plant();
meigui.name="玫瑰";
plant.sex="男";
System.out.println("类变量可以直接调用:"+plant.sex);
student area=new student();
double s = area.circle(2);
System.out.println("圆的面积为:"+s);
double x = new student().circle(2);
System.out.println("圆的面积为:"+x);
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-3033.html