James Thomas
James Thomas

Reputation: 11

ActionScript 3.0: Class Relationships

Im having trouble understanding class relationships after being asked to research it further, would anyone be able to help?

If I were to create 'Class A', and Class A has all the attributes and methods we need for a new class C, but class C requires at least 3 new methods and 3 new attributes, is it possible to form a relationship between Class A and C, and if so, what kind of relationship would that be?

Upvotes: 0

Views: 99

Answers (3)

Dr.Denis McCracleJizz
Dr.Denis McCracleJizz

Reputation: 870

You can think of class inheritance like the following.

You have a Class Automobile. It has a motor, a frame, a fuel tank, wheels.

From there you can inherit/extend Automobile class to create a Racing Car.

Racing Car has a motor, a frame, fuel tank, wheels, but it also has air conditioning and a radio.

Another example would be a bulldozer, it has a motor, a frame, a fuel tank, wheels, no air conditioning but it has a Shovel in front of it etc...

Upvotes: 0

sch
sch

Reputation: 27536

This is called inheritance.

  • C inherits from A.
  • C is a subclass (or child class) of A.
  • A is the superclass (or parent class) of C.

This can be achieved like the following in as3:

public class C extends A
{
    public function C()
    {
        super(); // The constructor of class A
    }

    public function methodC1()
    {

    }

    // ...
}

Upvotes: 3

Eric
Eric

Reputation: 10658

Class C extends A

All the attributes and methods, if public, of class A will be inherited to Class C

Upvotes: 1

Related Questions