/**
* 对象的创建和使用
* @author lin
*
*/
public class Test {
public static void main(String[] argrs){
/*
// 声明一个Person类型的变量,变量名为person,实例化Person类,并且给person复制
Person person = new Person();//new Person()就是实例化Person类
person.name = "法外狂徒";//给person对象的name属性赋值
person.showName();//对象方法的调用
System.out.println(person.getAge());
person.age = 10;//给person对象的age属性赋值
int a = person.getAge();
System.out.println(a);
//实例化animal对象
Animal ani = new Animal();
ani.eat("大米");
ani.move("跑");
//实例化学生对象
Student stu = new Student();
stu.name = "法外狂徒";
stu.age = 30;
stu.course = "枪法、狙击、五十公里越野跑";
stu.interest = "狙击";
stu.showInfo();
Teacher tea = new Teacher();
tea.name = "无极剑圣";
tea.major = "剑道";
tea.course = "悟剑、疾跑";
tea.teachAge = 3;
tea.showInfo();
//创建person1的实例对象
Person1 per = new Person1();
per.name = "蒸汽机器人";
per.age = 20;
per.sex = "男";
per.study();
per.showAge();
System.out.println(per.addAge());
System.out.println("半径为2圆的面积:" + new Circle().area(2));
*/
new lianxi().mOL(2);
new lianxi().mOL(2, 4);
new lianxi().mOL("mao");
new lianxi().max(10, 5);
new lianxi().max(10.1,20.2);
new lianxi().max(100, 20.1, 10);
}
}
代码练习--对象的创建与使用
猜你喜欢
转载自blog.csdn.net/weixin_42248871/article/details/109227501
今日推荐
周排行