<h2>Question</h2>
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 ( );
}
<h2>
Answer:</h2>
(b)
public abstract class Rectangle {
public abstract double findArea ( );
}
<h2>
Explanation:</h2>
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:
<em>[access_modifier]</em> abstract class <em>[name_of_class]</em>
[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 <em>option b</em> where;
(i) The access modifier is public
(ii) The name of the class is Rectangle
Option a is not correct because the <em>abstract</em> keyword is supposed to come before the <em>class</em> keyword.
Option c is not correct because the keyword <em>abstract</em> is missing. In other words, the class must be declared abstract since it contains abstract method findArea();
Option d is not correct because the <em>abstract</em> keyword is supposed to come before the <em>class</em> keyword.