• No results found

Deel 5: Inheritance Subclass in extension inheritance kunnen uitleggen. Extension

N/A
N/A
Protected

Academic year: 2021

Share "Deel 5: Inheritance Subclass in extension inheritance kunnen uitleggen. Extension"

Copied!
3
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

1

Deel 5: Inheritance

Subclass in extension inheritance kunnen uitleggen.

Extension inheritance is a type of inheritance where the subclass inherits all the characteristics and all the methods defined at the level of its superclass, without any change to those.

Java uses the keyword extends to indicate that this class inherits from a superclass. Subclasses inherit all the instance methods and all the instance variables. The implementation of the methods and variables is left untouched in extension inheritance. Java subclasses do not inherit static methods and static variables from their superclass. Constructors are not inherited either, as constructors are static methods. You can invoke the constructor of the superclass by callng super(…) as the first line of code in the constructor of your subclass.

In extending subclasses, the subclass introduces new instance properties and class properties, which will only apply to the subclass itself.

Open-closed principle:

Grant subclasses access to getters and setters defined at the level of their superclass by qualifying them (at least) protected. This means that classes, models, function, etc.

should be open for extension, but closed for modification.

Abstract class in extension inheritance kunnen uitleggen

An abstract method is a method that has no implementation specified in the superclass.

Thus, a subclass must override them, it cannot simply use the version defined in the superclass. Therefore, that class becomes an abstract class. So the sole purpose of an abstract class is to introduce characteristics an behaviour common to a series of subclasses that inherit from it. Every abstract class inherits from the concrete Object class. Abstract class can inherit from concrete classes and vice versa. An abstract class cannot have any objects of its own.

Good to know

Method overloading happens in the same class, shares the same method name but each method should have different number of parameters or parameters having different types and order. But in method overriding, derived class have the same method with same name and exactly the same number and type of parameters and the same return type as a parent class.

Good to know

Object class is present in java.lang package. Every class in Java is directly or indirectly derived from the Object class. E.g. toString(), equals(), etc.

(2)

2 Polymorphism kunnen uitleggen

There is distinction between a static and a dynamic type of a variable. The static type of a variable is the type stated in its declaration. The dynamic type of a variable is the type of the contents that the variable currently store.

The static type of test is DiskItem, and the dynamic type is File.

You can only invoke methods to a reference variable if the statictype (class) that has that method implemented or if you type cast that variable to such a class. See the resume on page 6 for an example.

The static type of a variable with value semantics is at all times the same as its dynamic type.

Overriding of methods kunnen uitleggen.

Subclasses can work out a more appropriate/specific implementation of instance methods they inherit from their superclass. Concrete subclasses that inherit from an abstract superclass must work out an implementation of each abstract method they inherit. Also, develop class hierarchies in such a way that any extension with new subclasses has no impact at all on the definition of existing classes in the hierarchy.

When overriding abstract methods at the level of a subclass, the only changes that are allowed are the return type that can be replaced by a subtype, the access rights can be widened and thelist of exceptionscan be shortened. The compiler interprets the method as a new one if these rules are not respected.

When overriding concrete methods at the level of a subclass, the versions of all methods defined at the level of its superclass are still available.

Dynamische binding kunnen uitleggen.

Given the fact that several versions of an instance method can exist throughout a hierarchy of classes, dynamic binding selects the version to be executed based on the dynamic type of the expression whose evaluation yields the prime objects. The selection of the actual version of the method to be executed is performed at runtime.

Example DiskItem:

DiskItem test;

File file1 = new File();

Test = file1;

(3)

3

A final method cannot be overridden at the level of a direct or indirect subclass.

Referenties

GERELATEERDE DOCUMENTEN

The inductive approach of [6] was successfully used to prove Gaussian asymptotic behavior for the Fourier transform of the critical two-point function c n (x; z c ) for a

technologies. Although there is a small negative relationship with perceived usefulness as a mediator, a stronger positive relationship is found with subjective norm as mediator.

Given the best efforts of multiple GWAS for many complex disorders, even outputs that are seemingly notable (i.e. identification of 108 independent genomic SZ

Meeting the Future: Christian Leadership in South Africa, Randburg: Knowledge Resources, 163-174; in a very informative essay where he summarized his own understanding

With this model function we have also been able to separate the glory and attractive contribution to Q, and using the results from the extrapolation

macro \@wiledo; we use the counter \cifra to count and point to the position of a character and we cycle trough all the 16 fiscal code characters; on the first run when \cifra

If you need a list of all entry labels for the use of an editor or helper script you may also want to consider the package options writeglslabels and writeglslabelnames provided by

A well-formed system architecture is consistent ifthe individual components are consis- tentand appropriate components are plugged into the placeholders, i.e., if a component is