设计网站推荐p,网站拓扑图怎么做,wordpress html地图,建一个论坛网站要多少钱类和对象的使用
创建类#xff0c;设计类的成员创建类的对象通过“对象.属性”或“对象.方法”调用对象的结构
代码
public class Per {public static void main(String[] args) {// TODO Auto-generated method stub//创建Person类的对象Person p1 new Person();//Scanne…类和对象的使用
创建类设计类的成员创建类的对象通过“对象.属性”或“对象.方法”调用对象的结构
代码
public class Per {public static void main(String[] args) {// TODO Auto-generated method stub//创建Person类的对象Person p1 new Person();//Scanner scanner new Scanner(System.in);//调用对象的结构属性方法//调用属性对象属性p1.name Tom;p1.isWoman true;System.out.println(p1.name);System.out.println(p1.isWoman);//调用方法对象方法p1.eat();p1.sleep();p1.talk(中文);p1.job(学生);}
}class Person{//属性String name;int age 1;boolean isWoman;//方法public void eat() {System.out.println(人可以吃饭);}public void sleep() {System.out.println(人可以睡觉);}public void talk(String language) {System.out.println(人说的语言是 language);}public void job(String career) {System.out.println(人的职业是 career);}
}
运行结果