asked 211k views
0 votes
What is the error in the following class definitions?

Abstract class xy
{
abstract sum (int x, int y) { }
}
(a) Class header is not defined properly.
(b) Constructor is not defined.
(c) Method is not defined properly
(d) Method is defined properly
(e) No error.

asked
User Arden
by
7.8k points

1 Answer

3 votes

Final answer:

The error in the class definitions is that the abstract method 'sum' is improperly defined with an empty body. Abstract methods should be declared without a body, ending with a semicolon.

Step-by-step explanation:

The error in the following class definitions is that the method is not defined properly. In an abstract class, abstract methods can have no body. However, in the given class definition, the abstract method sum(int x, int y) has an empty body indicated by the curly braces { }. The correct way to define an abstract method in Java is to end the method declaration with a semicolon instead of providing an empty body. The correct definition should be:

abstract class xy {
abstract void sum(int x, int y);
}

Therefore, the correct answer to the student's question is (c) Method is not defined properly.

answered
User Susie Humby
by
9.1k points