java - The constructor (constructor name) is undefined -
java - The constructor (constructor name) is undefined -
i'm trying create code able calculate area , perimeter of rectangles dimensions user input. of when seek phone call rectangle class create new rectangle, compiler says rectangle constructor undefined.
import java.util.scanner; public class rectangles { public class rectangle { public rectangle() {} public int length; public int width; public rectangle(int len, int wid) { length = len; width = wid; } } public void runner() { scanner scanner = new scanner(system.in); string input1 = scanner.nextline(); string input2 = scanner.nextline(); rectangle first = new rectangle(input1, input2); //error here system.out.println(first); scanner.close(); } public static void main(string[] args) {} }
the error "the constructor rectangles.rectangle(java.lang.string, java.lang.string) undefined"
the error compiler has stated - have declared constructor takes 2 int
arguments, tried create rectangle
using 2 string
s. types incompatible. should either utilize scanner read int
or utilize 1 of utility methods in integer
class convert string
int
or integer
. should aware of coding standards such capitalised class names.
java constructor
Comments
Post a Comment