你的翻译好像有点容易产生误会。第八题原文是这样的: Create a class without a constructor, and then create an object of that class in main( ) to verify that the default constructor is automatically synthesized.题目要你做的好像就是:“创建一个没有构造器的类,并在main()中创建其对象”我的理解是这样的
验证这个类的固有方法 例如toString
class MyType { public static void main(String[] args) { new MyType(); //虽然类中没有定义构造函数MyType(),但这里却调用了MyType(),由此可见编译器自动为你添加了MyType()这个构造函数。 } }
class a{ public static void main(String[] args){ new a(); } } //完毕
就是这样啊???我看完题写了一个 class A { public static void main(string[] args) { A a=new A(); } }看着这个,我怎么想,怎么觉得不对~~题目怎么会这么要求呢~
Create a class without a constructor, and then create an object of that class in main( ) to verify that the default constructor is automatically synthesized.题目要你做的好像就是:“创建一个没有构造器的类,并在main()中创建其对象”我的理解是这样的
public static void main(String[] args) {
new MyType(); //虽然类中没有定义构造函数MyType(),但这里却调用了MyType(),由此可见编译器自动为你添加了MyType()这个构造函数。
}
}
public static void main(String[] args){
new a();
}
}
//完毕
class A
{
public static void main(string[] args)
{
A a=new A();
}
}看着这个,我怎么想,怎么觉得不对~~题目怎么会这么要求呢~