Skip to content

Commit

Permalink
继承Java、Kotlin对比实现
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterZhang committed Jun 28, 2017
1 parent 2d4b86f commit 5ee5d2a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/com/betterzhang/learnkotlin/java/People.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.betterzhang.learnkotlin.java;

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 上午 10:00
* Desc : description
*/
public class People {

private String name = null;

public People(String name) {
this.name = name;
}

public void sayHello() {
System.out.println("Hello Java");
}

public final void sayGood() {
System.out.println("Good");
}

}
25 changes: 25 additions & 0 deletions src/com/betterzhang/learnkotlin/java/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.betterzhang.learnkotlin.java;

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 上午 10:02
* Desc : description
*/
public final class Student extends People {

private String school = null;

public Student(String name, String school) {
super(name);
this.school = school;
}

@Override
public void sayHello() {
super.sayHello();
System.out.println("Hello Student");
}

}
15 changes: 15 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/People.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.betterzhang.learnkotlin.kotlin

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 上午 10:15
* Desc : description
*/
open class People(private var name: String? = null) {

open fun sayHello() = println("Hello Kotlin")
fun sayGood() = println("Good")

}
17 changes: 17 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/Student.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.betterzhang.learnkotlin.kotlin

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 上午 10:17
* Desc : description
*/
class Student(private var school: String? = null, name: String) : People(name) {

override fun sayHello() {
super.sayHello()
println("Hello Student")
}

}

0 comments on commit 5ee5d2a

Please sign in to comment.