Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有日历的构造函数-新对象_Java_Calendar - Fatal编程技术网

Java 具有日历的构造函数-新对象

Java 具有日历的构造函数-新对象,java,calendar,Java,Calendar,我的代码: public MyCode (Calendar example1, String example2){ this.example1 = new GregorianCalendar(); this.example2 = example2; } 如何使用参数创建对象?下面是一个仅使用getMethods的构造函数的类示例 public class MyCode { private GregorianCalendar example1 = null;

我的代码:

public MyCode (Calendar example1, String example2){    
    this.example1 = new GregorianCalendar();
    this.example2 = example2;    
}

如何使用参数创建对象?

下面是一个仅使用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;
  } 
}
我建议阅读评论和下面的教程

该类的用法如下所示

MyCode myfirstObject = new MyCode(new GregorianCalendar(),"My First Object");

你到底是什么意思?如何创建MyCode的对象?您至少看过文档了吗?你想要实现什么?你在谈论什么参数?你可以。MyObject nameObject=new(???,“我的文本”)<代码>