Actual and formal arguments Differ in length- Java Constructor error -
i starting learn java , ran problem can't solve. have class called myclass constructor. want set constructor access private field:
public class myclass{ private long variable1; public myclass(long variable1){ this.variable1=variable1; } public long somethingelse(argument argument){ return somevalue; } }
i can call somethingelse class when remove constructor. however, when try along lines
data = new myclass(); return data.somethingelse(argument);
i error @ data = new myclass() actual , formal arguments differ in length , "requires long, found no arguments". how fix this?
from here:
the compiler automatically provides no-argument, default constructor class without constructors
when explicitly add constructor, override default no-arg one. so, back, add manually:
public class myclass{ private long variable1; // need add. public myclass() { } public myclass(long variable1){ this.variable1 = variable1; } public long somethingelse(argument argument){ return somevalue; } }
Comments
Post a Comment