-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package Basics.Extends_demo1; | ||
|
||
// https://www.youtube.com/watch?v=ArTiU9HR5Kw&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=259 | ||
|
||
public class ExtendsTest { | ||
public static void main(String[] args){ | ||
Person p1 = new Person(); | ||
p1.age = 30; | ||
System.out.println("p1.age = " + p1.age); | ||
p1.eat(); | ||
|
||
System.out.println("=================="); | ||
|
||
Student s1 = new Student(); | ||
s1.age = 20; | ||
System.out.println("s1.age = " + s1.age); | ||
s1.sleep(); | ||
s1.study(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package Basics.Extends_demo1; | ||
|
||
// https://www.youtube.com/watch?v=ArTiU9HR5Kw&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=259 | ||
|
||
public class Person { | ||
// attr | ||
String name; | ||
int age; | ||
|
||
// constructor | ||
public Person(){ | ||
} | ||
|
||
public Person(String name, int age){ | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
// method | ||
public void eat(){ | ||
System.out.println("eat @@@@"); | ||
} | ||
|
||
public void sleep(){ | ||
System.out.println("sleep !!!!!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package Basics.Extends_demo1; | ||
|
||
// https://www.youtube.com/watch?v=ArTiU9HR5Kw&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=259 | ||
|
||
public class Student extends Person { | ||
// attr (we can use the attr, method that Person already defined) | ||
String major; | ||
|
||
// constructor | ||
public Student(){ | ||
} | ||
|
||
public Student(String name, int age, String major){ | ||
this.name = name; | ||
this.age = age; | ||
this.major = major; | ||
} | ||
|
||
// method (we can use the attr, method that Person already defined) | ||
public void study(){ | ||
System.out.println("i am study ~~~~"); | ||
} | ||
} |