Reputation: 11
Im making a basic program that creates an object with certain attributes, and it works fine, but I need to load it as a independent program itself, so I created another class called Lanzador, which calls the constructor from the other class so that it can create the objects.
Im new to this so I dont really know what I'm doing here:
public class Lanzador
{
public static void main(String args[]) {
TipodeTirada tirada = new TipodeTirada(String,String,int,String,boolean,int,boolean);
}
}
The problem is that I dont know how to really do this, since it still gives me an "int.class" expected.
What should I do so that when I start the program it lets me input the attributes (stirng, int, etc) ?
Thanks a lot.
Upvotes: 0
Views: 1603
Reputation: 15992
This :
TipodeTirada tirada = new TipodeTirada(String,String,int,String,boolean,int,boolean);
Doesn't exist in Java
. Even when declaring a method, you will have to give a name to your parameters :
public void myFunction(String param1, int param2)
{
...
}
It does exist in C language
but it's another problem.
Here, you want to create an instance of TipodeTirada
, so you have to pass actual values when calling the method, for example :
TipodeTirada tirada = new TipodeTirada("String 1","String 2",1,"String 3",true,2,false);
Supposing you have a class TipodeTirada
like this :
public class TipodeTirada {
String name, surname, value;
int age, weight;
boolean bool1, bool2;
}
Then you'll have your constructor inside like this :
public TipodeTirada(String name,String surname,int age,String value,boolean bool1,int weight,boolean bool2)
{
this.name = name;
this.surname = name;
// etc...
}
So what you're doing is creating a method that you're now calling inside your main
that assigns your parameters values to your TipodeTirada's instance's fields.
Upvotes: 0
Reputation: 159784
You need to supply actual values to your constructor rather than type keywords. Passing in the keywords will only make the compiler complain as its expecting literal values. Instead you could use, (for example):
new TipodeTirada("some value", "value2", 100, "value 3" ,false, 200, true);
Upvotes: 1
Reputation: 41945
TipodeTirada tirada = new TipodeTirada("a","b",1,"c",false,2,true);
you need to send actual values to constructor
Note: "a","b" and all are dummy values put values that make sense in your scenario.
Upvotes: 1