Advanced Programming Language Concepts
Advanced Programming Language Concepts
Advanced Programming Language Concepts
Concepts
CT006-3-3-APLC and Version VC1
1. Classes
2. Inheritance
3. Single Inheritance
4. Multiple Inheritances
5. Generic classes
However, all shapes will have a centre, and all centres can be
moved, but we don’t allow subclasses to have their own move
methods (hence the word, final).
All actual shapes, i.e. subclasses, may have further methods and
attributes, to achieve specialisation.
Mammal
Flier abstract Bird abstract
abstract
wingSpan eggSize
gestationTime
class Animal
{
private:
float weight;
float height;
public:
// some methods
}
Mammal Flier
Bird abstract
Method1( ) Method1( )
eggSize
overridden overridden
Bat
Cat Eagle Penguin
Method1( )
inherited
Function, vSort, given a list of any type, sorts the list giving the result as a
string (for printing). Class Ord is required for ordering any type (using < ) and
class Show is required for converting any type into a string (using show function).
class Stack
{ // a Stack has elements that are objects
private Object [ ] elements;
private int depth;
Stack st;
String s, t;
Circle c, d;
....
st = new Stack(100);
s = “Fred”;
c = new Circle(10.0);
....
st.push(s);
st.push(c);
....
t = (String)st.pop(); // casting
d = (Circle)st.pop(); // required
st = new Stack(50);
s = “Fred”;
st.push(s);
....
t = (String)st.pop(); // casting
Also, note that the elements must be objects and cannot be primitive (or
basic) types, such as int, float, etc)! To include such types, they would have to
be constructed and used as object types, such as Integer, Float (which are
classes rather than types!
This distinction between object and primitive types does not exist in
Haskell – nor in C#.
• Classes
• Inheritance
• Single Inheritance
• Multiple Inheritances
• Generic classes
Any Questions?