} } class Test extends Car.wheel{ Test(Car car){ car.super(); } public static void main(String [] args){ Car car = new Car(); Test test=new Test(car); } }引用.super()例子如上呀..
package cs1; 我差不多明白了 把以下两个做对比一下就知道了 import java.awt.*; public class Frame1 extends Frame { public Frame1(String title) { super(title);//*********就是这一句是啥意思?删除了还不行。! } public static void main(String args[]) { Frame1 test=new Frame1("WK"); test.setLocation(100,100); test.setSize(300,300); test.setVisible(true); } } 和 class Car { Car(){ System.out.println("car"); } class Wheel{ Wheel(){ System.out.println("wheel"); }
} } class Test extends Car.Wheel{ Test(Car car){ car.super(); } public static void main(String [] args){ Car car = new Car(); Test test=new Test(car); } }
super(title); 调用父类Frame的 public Frame(String title){ ... } 这样的构造函数。 super()调用的是 public Frame(){ ... }
是不是super.方法名()阿?
和method(super)?一个是调用超类的同名方法,如果不用super,在子类重写的情况下会被子类实现屏蔽
后面一个似乎是没办法编译通过吧
class wheel{
}
}
class Test extends Car.wheel{
Test(Car car){
car.super();
}
public static void main(String [] args){
Car car = new Car();
Test test=new Test(car);
}
}引用.super()例子如上呀..
我差不多明白了 把以下两个做对比一下就知道了
import java.awt.*;
public class Frame1 extends Frame
{
public Frame1(String title)
{
super(title);//*********就是这一句是啥意思?删除了还不行。!
}
public static void main(String args[])
{
Frame1 test=new Frame1("WK");
test.setLocation(100,100);
test.setSize(300,300);
test.setVisible(true);
}
} 和
class Car {
Car(){
System.out.println("car");
}
class Wheel{
Wheel(){
System.out.println("wheel");
}
}
}
class Test extends Car.Wheel{
Test(Car car){
car.super();
}
public static void main(String [] args){
Car car = new Car();
Test test=new Test(car);
}
}
调用父类Frame的
public Frame(String title){
...
}
这样的构造函数。
super()调用的是
public Frame(){
...
}
但是如果继承的是一个内部类,则需要使用 超类所在的类的实例.super()来调用超类的构造方法
假设该内部类是非静态的情况