BreakerMC
BreakerMC

Reputation: 3

How can I call a method along with its parameters?

public class Testing{
private String firstName;
private String lastName;
private double salary;
private String subject;
private String highestDegree;
private int years;


public Testing 
(String first, String last, String sub, String degree, double sal, int year)
//constructor being called in the main method.
    {
        lastName = last;
        firstName = first;
        subject = sub;
        highestDegree = degree;
        salary = sal;
        years = year;
    }
public class Hello{

 public static void main(String []args){
    //Part missing
 }
}

I did the setters and getters, all I'm missing is how to call that constructor in the main method. I was thinking on creating a new object like Testing in = new Testing() but I'm pretty sure I'm missing something else. And if there's more things that I might be missing please let me know. I'm learning java.

Upvotes: 0

Views: 49

Answers (1)

Devendra Lattu
Devendra Lattu

Reputation: 2802

Since you have defined a custom Constructor
public Testing (String first, String last, String sub, String degree, double sal, int year)
you cannot use the default constructor.

Testing in = new Testing() // Not allowed now

You would have to use your constructor to define, instantiate, and initialize objects of class Testing.

public static void main(String []args){
    String first = "userName";
    ...
    ...

    Testing in = new Testing(first, last, sub, degree, sal, year)
}

Upvotes: 2

Related Questions