Add interfaces and abstract
This commit is contained in:
27
interface.md
27
interface.md
@ -5,3 +5,30 @@ url: https://git.haw-hamburg.de/pm1-tutorium/slides
|
||||
header: Programmieren 1 **Tutorium**
|
||||
footer: Henri Burau und Eva Meinen
|
||||
-->
|
||||
|
||||
# Interfaces
|
||||
|
||||
Schnittstelle
|
||||
|
||||
nur Methodendeklaration (öffentliche Methoden)
|
||||
|
||||
```java
|
||||
interface Shape {
|
||||
double getArea();
|
||||
String toString();
|
||||
}
|
||||
```
|
||||
---
|
||||
|
||||
Erbende Klassen implementieren ein Interface (auch mehr als eines möglich)
|
||||
|
||||
```java
|
||||
class Circle implements Shape {
|
||||
private double radius;
|
||||
double getArea(){
|
||||
return 3.14 * radius * radius;
|
||||
}
|
||||
String toString() {
|
||||
return "Circle";}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user