public class Student extends Object { }
public class StudentTest {public static void main(String[] args) {
Student s = new Student();Class c = s.getClass();
String str = c.getName();
System.out.println(str);
}
}
Class c = s.getClass(); 我的理解:这是类Student的的对象s调方法getClass(),方法getClass()是哪来的?
这里的 Class c 中的c是不是StudentTest的一个对象?
为什么不写StudentTest c=s.getClass()?
String str = c.getName(); 这个更不懂了
这两句有点不懂,有人指点两句么?感激不尽
public class StudentTest {public static void main(String[] args) {
Student s = new Student();Class c = s.getClass();
String str = c.getName();
System.out.println(str);
}
}
Class c = s.getClass(); 我的理解:这是类Student的的对象s调方法getClass(),方法getClass()是哪来的?
这里的 Class c 中的c是不是StudentTest的一个对象?
为什么不写StudentTest c=s.getClass()?
String str = c.getName(); 这个更不懂了
这两句有点不懂,有人指点两句么?感激不尽
这里的 Class c 中的c是不是StudentTest的一个对象? 不是
为什么不写StudentTest c=s.getClass()?
String str = c.getName(); 这个更不懂了
这两句有点不懂,有人指点两句么?感激不尽 s.getClass(),说明s对象有getClass这个方法,s是对象Student 的实例,getClass方法是Object方法,Student集成了Object所以能调用
Class c 是s.getClass();的一个返回值,他返回的类型是Class对象,所以不能让StudentTest 类接收
从你提的问题来看应该接触java时间很短,不要把精力放在一些对你来说没有实际意义的代码上,买本好书循序渐进的学,你提的那些问题自然就会了。不要盲人摸象,事倍功半。
A a=new A();
a.getClass() 返回这个对象a的Class对象,所有的A类的对象都共享一个Class对象。
getName(),以String 的形式返回此 Class 对象所表示的实体(类、接口、数组类、基本类型或 void)名称。
a.getClass().getName() 返回 类A的名称XX.A 前面为A的文件路径