|
|
|
@ -93,7 +93,9 @@ class Human {
|
|
|
|
this.name = name;
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
class HelloWorld{
|
|
|
|
class HelloWorld{
|
|
|
|
void main(String[] args){
|
|
|
|
void main(String[] args){
|
|
|
|
Human matt = new Human("Matthew");
|
|
|
|
Human matt = new Human("Matthew");
|
|
|
|
@ -115,7 +117,9 @@ class SuperHuman extends Human {
|
|
|
|
return this.power;
|
|
|
|
return this.power;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
class HelloWorld{
|
|
|
|
class HelloWorld{
|
|
|
|
void main(String[] args){
|
|
|
|
void main(String[] args){
|
|
|
|
SuperHuman superman = new SuperHuman("Clark", "flight");
|
|
|
|
SuperHuman superman = new SuperHuman("Clark", "flight");
|
|
|
|
@ -127,7 +131,7 @@ class HelloWorld{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Abstract/Interface
|
|
|
|
## Abstract
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
```java
|
|
|
|
abstract class Car {
|
|
|
|
abstract class Car {
|
|
|
|
@ -136,13 +140,17 @@ abstract class Car {
|
|
|
|
System.out.println("screeeeech");
|
|
|
|
System.out.println("screeeeech");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
class Sedan extends Car{
|
|
|
|
class Sedan extends Car{
|
|
|
|
void drive(){
|
|
|
|
void drive(){
|
|
|
|
System.out.println("vroom");
|
|
|
|
System.out.println("vroom");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
class HelloWorld{
|
|
|
|
class HelloWorld{
|
|
|
|
void main(String[] args){
|
|
|
|
void main(String[] args){
|
|
|
|
Sedan myCar = new Sedan();
|
|
|
|
Sedan myCar = new Sedan();
|
|
|
|
@ -152,17 +160,23 @@ class HelloWorld{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
```java
|
|
|
|
interface Bird {
|
|
|
|
interface Bird {
|
|
|
|
void fly();
|
|
|
|
void fly();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
class Swallow implements Bird {
|
|
|
|
class Swallow implements Bird {
|
|
|
|
public void fly() {
|
|
|
|
public void fly() {
|
|
|
|
System.out.println("sweeeee");
|
|
|
|
System.out.println("sweeeee");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
class HelloWorld{
|
|
|
|
class HelloWorld{
|
|
|
|
void main(String[] args){
|
|
|
|
void main(String[] args){
|
|
|
|
Swallow stewart = new Swallow();
|
|
|
|
Swallow stewart = new Swallow();
|
|
|
|
|