public class Gzq{
Gzq(){
System.out.println("this is a Gzq!");
}
public static void main(String[] args){
//这里应该怎么写啊?
}
}
Gzq(){
System.out.println("this is a Gzq!");
}
public static void main(String[] args){
//这里应该怎么写啊?
}
}
public class Gzq{
Gzq(){
System.out.println("this is a Gzq!");
}
public static void main(String[] args){
Gzq pp=new Gzq();
pp.Gzp();
}
}
还有一种情况就是楼上说的直接new 一个class ,
例如:
class A{
A()
{
//无参的构造
this("str");//这句调用下边带参的构造 。
}
A(String str1)
{
}}
pp.Gzp();
构造方法不能直接调用的Gzq pp=new Gzq(); 这句执行时,会自动调用无参的构造。如果你写上参数,就调用对应参数列表的构造