首页 > 其他 > 详细

5.2 Object类的getClass()方法

时间:2015-10-25 12:25:28      阅读:178      评论:0      收藏:0      [点我收藏+]
public class Student extends Object{

}

/*
 * public final Class getClass():返回此 Object 的运行时类
 * 		Class类的方法:
 * 			public String getName():以 String 的形式返回此 Class 对象所表示的实体
 */
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); // cn.itcast_01.Student

		// 链式编程
		String str2 = s.getClass().getName();
		System.out.println(str2);
	}
}


5.2 Object类的getClass()方法

原文:http://my.oschina.net/u/2001589/blog/521707

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!