Suppose I have a class with a constructor that takes in two strings
is it okay to write the constructor this way?

public class box{
     private String s1;
     private String s2;   
public box(**String str1,String str2**){
    s1=str1;
    s2=str2; }
}

Or can I just say

public box(String str1,str2)?

public box(String str1,str2)

this will show error
constructor is similar like methods each argument has its own type
check this

Your java compiler would have answered that faster than anyone at DaniWeb could have done!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.