-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChallenge_28.java
54 lines (48 loc) · 1.33 KB
/
Challenge_28.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package challenge21_30;
/**
* default access modifier
* we access it from the same class and the same package.
* protected access modifier
* we access it from the same class,
* the same package and from the subclasses even in another package.
*
* abstract class only for implementation purpose, so no way to instatiate the abstract class.
*
*
*/
public class Challenge_28 {
static abstract class Simpson{
void talk(){
System.out.println("Simpson");
}
protected void prank(String prank){
System.out.println(prank);
}
}
static class Bart extends Simpson{
String prank;
public Bart( String prank ) {
this.prank = prank;
}
protected void talk(){
System.out.println("Eat my shorts!");
}
void prank(){
super.prank(prank);
System.out.println("Knock Homer down");
}
}
static class Lisa extends Simpson{
void talk(String toMe){
System.out.println("I love Sex");
}
}
public static void main( String[] args ) {
new Lisa().talk("sex");
Simpson simpson = new Bart("D'oh");
simpson.talk();
Lisa lisa = new Lisa();
lisa.talk();
((Bart) simpson).prank();
}
}