August 2000
JP219 : JAVA PROGRAMMING

QUESTION 5

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 5

(a) Explain what is meant by an abstract method in Java. [1 mark]

(b) Explain what is meant by an abstract class, and how it may relate to abstract methods. [2 marks]

(c) Write the abstract class Shape, such that it contains two public abstract methods, area and circumference, both of which are declared to return a double and take no parameters, and a member a, which is of type double, and can be inherited by any subsequent derived classes. [3 marks]

(d) Implement the public class Rectangle, such that it inherits from the Shape class. Your class should contain the integer members width and height, such that they are not accessible outside the class, and public accessor methods which return their values. [4 marks]

(e) Add to your class a constructor function, which has parameters which initialise all the member variables appropriately. [3 marks]

(f) An inexperienced Java programmer now tries to write a program which attempts to create a Rectangle object. Explain the error he is likely to encounter in doing this, and why. [2 marks]