⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
仔细看了下,3、4颠倒了
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Parent
{
public String name;
public Parent(String pName)
{
this.name = pName;
}
}
class Test extends Parent
{
public Test(String Name)
{
super("kitty");
name = "hello";
}
}
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
}
}
程序没错啊,你的选项看不是很清楚。
看不清楚,请上一张清楚点的
如果你不先调用super,报如下错误
onstructor Parent in class Parent cannot be applied to given types;
如果子类调用父类构造器初始化参数,则使用关键字super,且必须在构造器的第一行,这是语法规定,否则会报错
另外,即便子类没有显示调用父类构造器,编译器也会自动加上super();语句,只不过隐式的