getClass()方法
- 返回实际对象类型
应用
- 判断存储类型是否一致
package Demo4;
public class Application {
public static void main(String[] args) {
Student student = new Student("王伟康",22,"男");
Student student1 = new Student("白熊",1,"女");
Class Class = student.getClass();
Class Class1 = student1.getClass();
if (Class==Class1){
System.out.println("这两个对象属于同一类型");
}else {
System.out.println("这两个对象不属于同一类型");
}
}
}