1

I want to call parameterized constructor from default constructor inside a public java class.

Can I achieve it?

public Rectangle()
{
Rectangle(10.5f,2.5f)     //this not working
}
public Rectangle(float length, float breadth)
{
code...
}
2
  • 4
    this(10.5f, 2.5f). Commented Aug 7, 2020 at 11:02
  • 1
    also, don't forget the closing ; Commented Aug 7, 2020 at 11:03

1 Answer 1

3

You can use the this keyword.

This should do the trick:

public Rectangle() {
    this(10.5f, 2.5f);
}

public Rectangle(float length, float breadth) {
    //code..
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.