Monday, 19 March 2012

LAB 03 July 2013 - Interface


Consider the following Printface interface, which is designed to standard printing status method for the class that implements it :

public interface Printface {
              public double goprint() ;
}

a) Write an abstract class CollegeMembers that implements Printface interface. This class also have a instance variable Name and ID. Goprint() is set as abstract method here and is not being implemented here.

b) Write a concrete subclass Lecturer that provide a concrete representation of the Collegemembers but does not provide any additional functionality . Implement Goprint() by printing the name and ID of the lecturer.

c) Write a concrete subclass Student that extends CollegeMembers and have additional instance variables passportno (string) , mykadno(string) and nationality (string) . Create necessary constructor for the class. This class should implement Goprint() based the rules below :
If nationality is not malaysian , print name, id and passport number
Else print name , id and mykadno

d) Create a driver class and write declarations for a reference lecturerA of type Lecturer and StudentB of type Student. Create new object for both class and refer the new objects by reference lecturerA and StudentB. Call both Goprint for each object.

No comments:

Post a Comment