You need to sign in to do that
Don't have an account?

Getting error for constructor
Hi,
I was going through practice session about constructors but my program keeps on failing
I used the code:
public class TestObject2{
private static final Integer DEFAULT_SIZE = 10;
Integer size;
//Constructor with no arguments
public TestObject2() {
this(DEFAULT_SIZE); // Using this(...) calls the one argument constructor
}
// Constructor with one argument
public TestObject2(Integer ObjectSize) {
size = ObjectSize;
}
}
and At Execute Anonymous Window Giving:
TestObject2 myObject1 = new TestObject2(42);
TestObject2 myObject2 = new TestObject2();
I am getting an error:
Line: 1, Column: 25
Constructor not defined: [TestObject2].<Constructor>(Integer)
What is wrong here?
I was going through practice session about constructors but my program keeps on failing
I used the code:
public class TestObject2{
private static final Integer DEFAULT_SIZE = 10;
Integer size;
//Constructor with no arguments
public TestObject2() {
this(DEFAULT_SIZE); // Using this(...) calls the one argument constructor
}
// Constructor with one argument
public TestObject2(Integer ObjectSize) {
size = ObjectSize;
}
}
and At Execute Anonymous Window Giving:
TestObject2 myObject1 = new TestObject2(42);
TestObject2 myObject2 = new TestObject2();
I am getting an error:
Line: 1, Column: 25
Constructor not defined: [TestObject2].<Constructor>(Integer)
What is wrong here?
your code is fine
make sure your TestObject2 class save Successfully without any error
can you send screenshort of TestObject2 class
Thanks
All Answers
your code is fine
make sure your TestObject2 class save Successfully without any error
can you send screenshort of TestObject2 class
Thanks