class a { a() { } String getname() { return "this is a."; } } class b extends a { b() { super(); } String getname() { return super.getname()+"but this is also b"; } } Class bclazz = b.class; a bx = new a(); try { bx = bclazz.newInstance(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } if(bx instanceof b) Log.w("Test", "this is instanceof b"); if(bx instanceof a) Log.w("Test", "this is instanceof a"); Log.w("Test", bx.getname());
[Result]
08-29 09:41:31.314: WARN/Test(14370): this is instanceof b
08-29 09:41:31.314: WARN/Test(14370): this is instanceof a
08-29 09:41:31.314: WARN/Test(14370): this is a.but this is also b
No comments:
Post a Comment