Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f1f8c8d

Browse files
add inheritance folder and its files
1 parent 57f8f66 commit f1f8c8d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

‎src/inheritance/Animal.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Animal {
2+
String family = "cats";
3+
}

‎src/inheritance/Cat.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
class Cat extends Animal {
3+
void meow(){
4+
System.out.print("meow");
5+
}
6+
7+
public static void main(String[] args) {
8+
9+
Cat mingming = new Cat();
10+
11+
//family is coming from Animal class
12+
System.out.print("call from Animal class, family is : `");
13+
System.out.print(mingming.family);
14+
System.out.println("`");
15+
16+
//meuw method is from Cat class
17+
System.out.print("call from Cat class, method will `");
18+
mingming.meow();
19+
System.out.println("`");
20+
21+
}
22+
23+
}
24+
25+
26+
27+
28+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /