Pergunta

My code:

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

How I do create objects with parameters?

Foi útil?

Solução

Below is an example of a class with a constructor with only 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;
  } 
}

I would suggest reading the tutorial in the comment and the following http://howtoprogramwithjava.com/object-oriented-programming-java-tutorial/

use of the class is as follows

MyCode myfirstObject = new MyCode(new GregorianCalendar(),"My First Object");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top