public class Rectangle {
public Rectangle(int width, int height) {
Rectangle x = new Rectangle(7, 9);
double d = x.getDiagonal();
System.out.println(d);
}
}
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
public class Rectangle {
public Rectangle(int width, int height) {
Rectangle x = new Rectangle(7, 9);
double d = x.getDiagonal();
System.out.println(d);
}
}
Please explain why you think there is something wrong.
If you get error messages, copy the full text and paste it here.
If wrong output, post the output and explain what is wrong with the output.
Please edit your post and wrap your code with code tags:
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.
it says the method getDiagonal is undefined for the type Rectangle
--- Update ---
it says the mehod getDiagonal() is undefined for the type Rectangle
Did you look in the API doc for the class Rectangle? Does it have a getDiagonal() method defined?
See the API doc: Java Platform SE 7
If you don't understand my answer, don't ignore it, ask a question.
it is in java.lang.object
What is that? A package or a class? Where are you seeing that in the documentation?it is in java.lang.object
Note: Java class names start with Uppercase letters. The correct spelling for the Object class starts with a capital O
If you don't understand my answer, don't ignore it, ask a question.
You need to read the API doc for the Rectangle class and see what methods it has.method getDiagonal is undefined for the type Rectangle
The compiler is not finding the method: getDiagonal
You must use methods that are defined for the class, you can not use undefined methods.
What do you want the code to do? The volunteers are here to help you write your code and get it to work.
We do not write code for you. Figure out what you want to do, write the code to do it and if you have problems with it, copy the code here and post your questions about the problems you are having.
Be sure to copy and paste the full text of any error messages.
If you don't understand my answer, don't ignore it, ask a question.