- class Userful
- {
- public void f()
- {
- System.out.println("Now in f method of super class");
- }
- public void g()
- {
- System.out.print("Now in g method of super class");
- }
- }
- class MoreUserful extends Userful
- {
- public void f()
- {
- System.out.println("Now in f method of derived class");
- }
- public void g()
- {
- System.out.println("Now in g method of derived class");
- }
- public void u()
- {
- System.out.println("Now in u method of derived class");
- }
- public void v()
- {
- System.out.println("Now in v method of derived class");
- }
- public void w()
- {
- System.out.println("Now in w method of derived class");
- }
- }
- class Test
- {
- public static void main(String[] args)
- {
- Userful[] x = { new Userful(), new MoreUserful() };
- x[0].f();
- x[1].g();
- ((MoreUserful)x[1]).u();
- }
- }
复制代码 别的我都明白但是((MoreUserful)x[1]).u(); 这句是什么意思 不明白 为什么要把类名加到对象前边 是怎么一回事 麻烦大神帮忙解读一下
|
|