我的代码:
public MyCode (Calendar example1, String example2){
this.example1 = new GregorianCalendar();
this.example2 = example2;
}
我如何使用参数创建对象?
答案 0 :(得分:0)
下面是一个带有只带getMethods
的构造函数的类的示例public class MyCode
{
private GregorianCalendar example1 = null;
private String example2 = null;
public MyCode(Calendar example1 , String example2)
{
this.example1 = example1
this.example2 = example2;
}
public GregorianCalendar getExample1 ()
{
return example1;
}
public String getExample2 ()
{
return example2;
}
}
我建议在评论和以下内容中阅读教程 http://howtoprogramwithjava.com/object-oriented-programming-java-tutorial/
使用该类如下
MyCode myfirstObject = new MyCode(new GregorianCalendar(),"My First Object");