hamzamac@live.com http://issuu.com/hamzamac
College Of Informatics and Virtual Education
NAME: Makame, Makame H PROGRAM: B Sc. Computer and Information Security COURSE NAME: Object Oriented Programing in Java COURSE CODE: CS 207 PART: Abstract classes
Problem Descriptions: This program code demonstrates on how to create and use abstract classes. An abstract class declares common attributes and behaviors of the various classes in a class hierarchy. An abstract class typically containing one or more abstract methods that subclasses must override if subclasses are to be concrete. The instance variables and the concrete methods of an abstract class are subjected to the normal rules of inheritance.
The code consist of three classes MyAbs class is an abstract as it contains an abstract method drawRect() and other non-abstract methods Abs extends the abstract class MyAbs, this class is not abstract since it has implemented the abstract method drawRect() of its super class, otherwise it has to be abstract. o It use the key word super to call the super constructor. The Main class in which Abs class objects is created and used.
Wednesday, March 14, 2012
hamzamac@live.com http://issuu.com/hamzamac import java.util.*;
abstract class MyAbs{ private int x,y;
MyAbs(int z,int k){ x=z; y=k;
}
int getXposition(){ return x; } int getYposition(){ return y; } public abstract void drawRect(); }
class Abs extends
MyAbs{
private String colour;
public Abs(int q,int w, String c){ super(q,w); setColour(c); }
Wednesday, March 14, 2012
hamzamac@live.com http://issuu.com/hamzamac public void drawRect(){ System.out.println("Height is "+getYposition()); System.out.println("Widht is "+getXposition()); System.out.println("Colour is "+colour ); } void setColour(String c){ colour=c; }
}
public class Main{
public static void main(String [] args){ Abs w=new Abs(4,6,"Red"); w.drawRect();
}
}
Wednesday, March 14, 2012