Java 类的构造

package com.hqyj.oop.classes;

/**
* 类 不同数据类型组成的抽象!
*/
public class Person {
public static void main(String[] args) {
Student s=new Student();
s.name="12";
s.age=12;
s.setScore(60);
System.out.println(s.age+s.name+s.score);
Student s1=new Student();
Student s2=new Student();
Student s3=s2;
System.out.println( s1==s2);//输出false
System.out.println(s2==s3);//输出true
}
/*总结:
1 .定义打印学生信息的方法,然后以name \age \score作为参数
2 . name\age\score是属于学生类的,因此可以使用参数为Student student3 .打印学生信息的方法属于学生类的行为,放在学生类中
4 .使用Student类,采用new Student();方式
5 .发现new Student();不能同时为同一个对象设置多个属性值6.采用引用的概念,Student s = new Student();
7.通过引用打点的方式,访问定义在类中的属性和方法。->s.name = "zhang3" ,s.studentInfo();! !!类就是一个数据类型!!!
*/



}
posted @ 2022-03-26 11:16  java小寇  阅读(56)  评论(0)    收藏  举报