构造方法
package com.java.chew;
public class Student {
int Id;
String name;
int age;
public Student(int Id, String name, int age){
this.Id = Id;
this.name = name;
this.age = age;
}
public int getId() {
return Id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
package com.java.chew;
public class StudentTest {
public static void main(String[] args) {
Student s = new Student(56 , "zhangsan" ,23);
System.out.println(s.getId());
System.out.println(s.getName());
System.out.println(s.getAge());
}
}
文章讲述了如何在Java中定义和使用构造方法,以及如何创建和访问Student类的对象属性。在Student类中,展示了属性定义和构造函数,而在StudentTest类中,通过实例化并调用构造方法获取对象属性。

9078

被折叠的 条评论
为什么被折叠?



