71.0k views
0 votes
Which of the following class definition defines a legal abstract class Group of answer choices public class Rectangle abstract { public abstract double findArea ( ); } public abstract class Rectangle { public abstract double findArea ( ); } public class Rectangle { public abstract double findArea ( ); } public class abstract Rectangle { public abstract double findArea ( ); }

1 Answer

1 vote

Question

Which of the following class definition defines a legal abstract class Group of answer choices

(a)

public class Rectangle abstract {

public abstract double findArea ( );

}

(b)

public abstract class Rectangle {

public abstract double findArea ( );

}

(c)

public class Rectangle {

public abstract double findArea ( );

}

(d)

public class abstract Rectangle {

public abstract double findArea ( );

}

Answer:

(b)

public abstract class Rectangle {

public abstract double findArea ( );

}

Step-by-step explanation:

When a class is declared with the abstract keyword, the class is called an abstract class. Abstract classes cannot be instantiated and may include one or more abstract methods. If a class contains an abstract method, then it (the class) must be declared abstract.

In Java, abstract classes are defined using the following format:

[access_modifier] abstract class [name_of_class]

[access_modifier] specifies the access modifier of the class which could be public, private, e.t.c

abstract is the keyword that specifies that the class is an abstract class.

class is a keyword used for defining classes

name_of_class specifies the name of the class.

The only option that fulfils this format is option b where;

(i) The access modifier is public

(ii) The name of the class is Rectangle

Option a is not correct because the abstract keyword is supposed to come before the class keyword.

Option c is not correct because the keyword abstract is missing. In other words, the class must be declared abstract since it contains abstract method findArea();

Option d is not correct because the abstract keyword is supposed to come before the class keyword.

User Rakesh Vadnal
by
4.6k points