Java Interface Modifiers in Class Hierarchy

ת
ו
כ
נ
ה
 
1
ת
ר
ג
ו
ל
 
מ
ס
פ
ר
 
1
2
:
S
u
m
m
e
r
y
 
1
1
ב
י
ת
 
ה
ס
פ
ר
 
ל
מ
ד
ע
י
 
ה
מ
ח
ש
ב
א
ו
נ
י
ב
ר
ס
י
ט
ת
 
ת
ל
 
א
ב
י
ב
2
ב
ח
י
נ
ה
 
ב
א
ו
פ
ק
!
ה
ב
ח
י
נ
ה
 
ת
כ
ל
ו
ל
 
א
ת
 
כ
ל
 
ה
נ
ו
ש
א
י
ם
 
ש
כ
י
ס
י
נ
ו
 
ב
מ
ה
ל
ך
 
ה
ס
מ
ס
ט
ר
:
כ
ל
 
ה
ה
ר
צ
א
ו
ת
כ
ל
 
ת
ר
ג
ו
ל
י
ם
כ
ל
 
ת
ר
ג
י
ל
י
 
ב
י
ת
ח
ו
מ
ר
 
ס
ג
ו
ר
ח
ל
ק
 
פ
ת
ו
ח
ח
ל
ק
 
א
מ
ר
י
ק
א
י
3
ק
צ
ת
 
ע
ל
 
מ
נ
ש
ק
י
ם
מ
נ
ש
ק
 
י
כ
ו
ל
 
ל
ה
ר
ח
י
ב
 
י
ו
ת
ר
 
מ
מ
נ
ש
ק
 
א
ח
ד
ש
י
ר
ו
ת
י
ם
 
ב
מ
נ
ש
ק
 
י
כ
ו
ל
י
ם
 
ל
ה
י
ו
ת
:
פ
ר
ט
י
י
ם
 
(
ה
ח
ל
ק
 
מ
-
j
a
v
a
 
9
)
צ
י
ב
ו
ר
י
י
ם
,
 
ו
כ
ב
ר
י
ר
ת
 
מ
ח
ד
ל
 
מ
ו
פ
ש
ט
י
ם
public interface
 
MyInterface {
 
public abstract int
 
foo1(
int
 i);
 
int
 
foo2(
int
 i);
}
 
The modifiers of foo1 and foo2 are the same.
4
מ
נ
ש
ק
י
ם
public interface
 
Foo {
 
  
public void
 
bar() 
throws
 Exception;
}
public class
 
FooImpl 
implements
 Foo {
    
public void
 
bar() {
      
 
System.
out
.println(
"No exception is thrown"
);
 
 
  }
 
  
public static void 
main(String args[]) {
  
Foo foo = 
new
 FooImpl();
  
foo.bar();
 
  }
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
5
מ
נ
ש
ק
י
ם
public interface
 
Foo {
 
  
public void
 
bar() 
throws
 Exception;
}
public class
 
FooImpl 
implements
 Foo {
    
public void
 
bar() {
      
 
System.
out
.println(
"No exception is thrown"
);
 
 
  }
 
  
public static void 
main(String args[]) {
  
Foo foo = 
new
 FooImpl();
  
foo.bar();
 
  }
}
ש
ג
י
א
ת
 
ק
ו
מ
פ
י
ל
צ
י
ה
:
"
U
n
h
a
n
d
l
e
d
 
e
x
c
e
p
t
i
o
n
 
t
y
p
e
 
E
x
c
e
p
t
i
o
n
"
6
מ
נ
ש
ק
י
ם
 
-
 
ה
מ
ש
ך
 
public interface
 
Foo {
 
public void
 
bar() 
throws
 Exception;
}
public class
 
FooImpl 
implements
 Foo {
  
 
public void
 
bar() {
      
 
System.
out
.println(
"No exception is thrown"
);
 
 
}
 
public static void 
main(String args[]) {
  
FooImpl foo = 
new
 FooImpl();
  
foo.bar();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
7
מ
נ
ש
ק
י
ם
 
-
 
ה
מ
ש
ך
 
public interface
 
Foo {
 
public void
 
bar() 
throws
 Exception;
}
public class
 
FooImpl 
implements
 Foo {
  
 
public void
 
bar() {
      
 
System.
out
.println(
"No exception is thrown"
);
 
 
}
 
public static void 
main(String args[]) {
  
FooImpl foo = 
new
 FooImpl();
  
foo.bar();
 
}
}
פ
ל
ט
:
"
N
o
 
e
x
c
e
p
t
i
o
n
 
i
s
 
t
h
r
o
w
n
"
8
מ
נ
ש
ק
י
ם
 
ו
י
ר
ו
ש
ה
Consider the following class hierarchy:
Interface
 
Animal {…}
class
 Dog 
implements
 
Animal{…}
class
 Poodle 
extends
 Dog {…}
class
 Labrador 
extends
 Dog {…}
Which of the following lines (if any) will not compile?
Poodle poodle = 
new
 Poodle();
Animal animal = (Animal) poodle;
Dog dog = 
new
 Labrador();
animal = dog;
poodle = dog;
D
o
g
L
a
b
r
a
d
o
r
P
o
o
d
l
e
A
n
i
m
a
l
9
מ
נ
ש
ק
י
ם
 
ו
י
ר
ו
ש
ה
Consider the following class hierarchy:
Interface
 
Animal {…}
class
 Dog 
implements
 
Animal{…}
class
 Poodle 
extends
 Dog {…}
class
 Labrador 
extends
 Dog {…}
Which of the following lines (if any) will not compile?
Poodle poodle = 
new
 Poodle();
Animal animal = (Animal) poodle;
Dog dog = 
new
 Labrador();
animal = dog;
poodle = dog;
poodle = (Poodle) dog;
A
n
i
m
a
l
D
o
g
L
a
b
r
a
d
o
r
P
o
o
d
l
e
-
 
Compilation Error
Type mismatch: cannot
convert from Dog to
Poodle
Labrador labrador = (Labrador) dog;
 
 
 
 
 
-
No compilation error
-
Runtime Exception
-
No compilation error
-
No Runtime Exception
10
10
מ
נ
ש
ק
י
ם
 
ו
י
ר
ו
ש
ה
class
 
A {
    
public
 
void
 print() {
        System.
out
.println(
"A"
);
   
 
}
}
class
 B 
extends
 A
 
implements
 C {
}
interface
 C {
    
void
 print();
}
ה
א
ם
 
י
ש
 
ש
ג
י
א
ה
?
11
11
מ
נ
ש
ק
י
ם
 
ו
י
ר
ו
ש
ה
class
 
A {
    
public
 
void
 print() {
        System.
out
.println(
"A"
);
   
 
}
}
class
 B 
extends
 A
 
implements
 C {
}
interface
 C {
    
void
 print();
}
א
י
ן
 
ש
ג
י
א
ו
ת
 
ק
ו
מ
פ
י
ל
צ
י
ה
p
u
b
l
i
c
 
כ
ב
ר
י
ר
ת
 
מ
ח
ד
ל
12
12
מ
נ
ש
ק
י
ם
 
ו
י
ר
ו
ש
ה
class
 
A {
  
void
 print() {
        System.
out
.println(
"A"
);
   
 
}
}
class
 B 
extends
 A
 
implements
 C {
}
interface
 C {
    
void
 print();
}
ה
א
ם
 
י
ש
 
ש
ג
י
א
ה
?
13
13
מ
נ
ש
ק
י
ם
 
ו
י
ר
ו
ש
ה
class
 
A {
  
void
 print() {
        System.
out
.println(
"A"
);
   
 
}
}
class
 B 
extends
 A
 
implements
 C {
}
interface
 C {
    
void
 print();
}
ש
ג
י
א
ת
 
ק
ו
מ
פ
י
ל
צ
י
ה
:
T
h
e
 
i
n
h
e
r
i
t
e
d
 
p
a
c
k
a
g
e
m
e
t
h
o
d
 
A
.
p
r
i
n
t
(
)
c
a
n
n
o
t
 
h
i
d
e
 
t
h
e
 
p
u
b
l
i
c
a
b
s
t
r
a
c
t
 
m
e
t
h
o
d
 
i
n
 
C
T
h
e
 
f
o
l
l
o
w
i
n
g
 
t
a
b
l
e
 
s
h
o
w
s
 
t
h
e
 
a
c
c
e
s
s
 
t
o
m
e
m
b
e
r
s
 
p
e
r
m
i
t
t
e
d
 
b
y
 
e
a
c
h
 
m
o
d
i
f
i
e
r
14
14
A
c
c
e
s
s
 
L
e
v
e
l
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
d
e
f
a
u
l
t
15
15
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
public
 
class
 A {
 
public
 
void
 print() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 print() {
  
System.
out
.println(
"B"
);
 
}
 
}
p
u
b
l
i
c
 
c
l
a
s
s
 
C
 
{
 
public
 
static
 
void
 main(String[]
args){
  
B b = 
new
 B();
  
A a = b;
  
b.print();
  
a.print();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
16
16
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
public
 
class
 A {
 
public
 
void
 print() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 print() {
  
System.
out
.println(
"B"
);
 
}
 
}
p
u
b
l
i
c
 
c
l
a
s
s
 
C
 
{
 
public
 
static
 
void
 main(String[]
args){
  
B b = 
new
 B();
  
A a = b;
  
b.print();
  
a.print();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
ה
פ
ל
ט
:
B
B
א
י
ן
 
צ
ו
ר
ך
 
ב
-
c
a
s
t
i
n
g
17
17
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
public
 
class
 A {
 
public
 
void
 print() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
protected
 
void
 print() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 C {
 
public
 
static
 
void
 main(String[]
args) {
  
B b = 
new
 B();
  
b.print();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
18
18
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
public
 
class
 A {
 
public
 
void
 print() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
protected
 
void
 print() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 C {
 
public
 
static
 
void
 main(String[]
args) {
  
B b = 
new
 B();
  
b.print();
 
}
}
ש
ג
י
א
ת
 
ק
ו
מ
פ
י
ל
צ
י
ה
:
"
C
a
n
n
o
t
 
r
e
d
u
c
e
 
t
h
e
v
i
s
i
b
i
l
i
t
y
 
o
f
 
t
h
e
i
n
h
e
r
i
t
e
d
 
m
e
t
h
o
d
 
f
r
o
m
 
A
"
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
19
19
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
2
)
public
 
class
 A {
 
protected void
 print() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
public void
 print() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 C {
 
public
 
static
 
void
 main(String[]
args) {
  
B b = 
new
 B();
  
b.print();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
20
20
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
2
)
public
 
class
 A {
 
protected void
 print() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
public void
 print() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 C {
 
public
 
static
 
void
 main(String[]
args) {
  
B b = 
new
 B();
  
b.print();
 
}
}
ה
פ
ל
ט
:
B
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
21
21
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
3
)
public
 
class
 A {
 
 public void
 foo() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
 
public static void
 foo() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 
BindingTest {
 
public
 
static
 
void
 
main(String args[]) {
        
B b = 
new
 B();
        b.foo();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
22
22
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
3
)
public
 
class
 A {
 
 public void
 foo() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
 
public static void
 foo() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 
BindingTest {
 
public
 
static
 
void
 
main(String args[]) {
        
B b = 
new
 B();
        b.foo();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
C
o
m
p
i
l
a
t
i
o
n
 
E
r
r
o
r
:
f
o
o
(
)
 
i
n
 
B
 
c
a
n
n
o
t
 
o
v
e
r
r
i
d
e
 
f
o
o
(
)
 
i
n
 
A
.
o
v
e
r
r
i
d
i
n
g
 
m
e
t
h
o
d
 
i
s
 
s
t
a
t
i
c
.
23
23
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
4
)
public
 
class
 A {
 
 public static void
 foo() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
 
public void
 foo() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 
BindingTest {
 
public
 
static
 
void
 
main(String args[]) {
        
B b = 
new
 B();
        b.foo();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
24
24
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
4
)
public
 
class
 A {
 
 public static void
 foo() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
 
public void
 foo() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 
BindingTest {
 
public
 
static
 
void
 
main(String args[]) {
        
B b = 
new
 B();
        b.foo();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
C
o
m
p
i
l
a
t
i
o
n
 
E
r
r
o
r
:
f
o
o
(
)
 
i
n
 
B
 
c
a
n
n
o
t
 
o
v
e
r
r
i
d
e
 
f
o
o
(
)
 
i
n
 
A
.
o
v
e
r
r
i
d
d
e
n
 
m
e
t
h
o
d
 
i
s
 
s
t
a
t
i
c
.
25
25
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
5
)
public
 
class
 A {
 
 private static void
 foo() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
 
public void
 foo() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 
BindingTest {
 
public
 
static
 
void
 
main(String args[]) {
        
B b = 
new
 B();
        b.foo();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
26
26
ד
ר
י
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
 
ו
נ
י
ר
א
ו
ת
 
(
5
)
public
 
class
 A {
 
 private static void
 foo() {
  
System.
out
.println(
"A"
);
 
}
}
public
 
class
 B 
extends
 A {
 
 
public void
 foo() {
  
System.
out
.println(
"B"
);
 
}
}
public
 
class
 
BindingTest {
 
public
 
static
 
void
 
main(String args[]) {
        
B b = 
new
 B();
        b.foo();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
Output:
 
B
27
27
S
t
a
t
i
c
 
b
i
n
d
i
n
g
 
(
o
r
 
e
a
r
l
y
 
b
i
n
d
i
n
g
)
Static binding: bind at 
compilation time
Performed if the compiler can resolve the binding at
compile time
Applied for
Static methods
Private methods
Final methods
Fields
28
28
B
i
n
d
i
n
g
public
 
class
 A {
 
public
 
void
 foo() {   
  
  
System.
out
.println(
"A.foo()"
);
 
}
 
public
 
void
 bar() {
   
  
System.
out
.println(
"A.bar()"
);
  
foo();
 
}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 foo() {
  
System.
out
.println(
"B.foo()"
);
 
}
 
public
 
static
 
void
 
main(String
[] args)
{
  
A a = 
new
 B();
  
a.bar();
 
}
}
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
29
29
B
i
n
d
i
n
g
public
 
class
 A {
 
public
 
void
 foo() {   
  
  
System.
out
.println(
"A.foo()"
);
 
}
 
public
 
void
 bar() {
   
  
System.
out
.println(
"A.bar()"
);
  
foo();
 
}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 foo() {
  
System.
out
.println(
"B.foo()"
);
 
}
 
public
 
static
 
void
 
main(String
[] args)
{
  
A a = 
new
 B();
  
a.bar();
 
}
}
ה
פ
ל
ט
:
A
.
b
a
r
(
)
B
.
f
o
o
(
)
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
30
30
B
i
n
d
i
n
g
 
(
2
)
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
public
 
class
 A {
 
private
 
void
 foo() {   
  
  
System.
out
.println(
"A.foo()"
);
 
}
 
public
 
void
 bar() {
   
  
System.
out
.println(
"A.bar()"
);
  
foo();
 
}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 foo() {
  
System.
out
.println(
"B.foo()"
);
 
}
 
public
 
static
 
void
 
main(String
[] args)
{
  
A a = 
new
 B();
  
a.bar();
 
}
}
31
31
B
i
n
d
i
n
g
 
(
2
)
ה
פ
ל
ט
:
A
.
b
a
r
(
)
A
.
f
o
o
(
)
ה
א
ם
 
ה
ק
ו
ד
 
מ
ת
ק
מ
פ
ל
?
 
א
ם
 
ל
א
,
 
ל
מ
ה
?
א
ם
 
כ
ן
,
 
ה
א
ם
 
י
ש
 
ש
ג
י
א
ת
 
ר
י
צ
ה
?
 
א
ם
 
י
ש
,
 
ל
מ
ה
?
א
ח
ר
ת
,
 
מ
ה
 
ה
פ
ל
ט
?
public
 
class
 A {
 
private
 
void
 foo() {   
  
  
System.
out
.println(
"A.foo()"
);
 
}
 
public
 
void
 bar() {
   
  
System.
out
.println(
"A.bar()"
);
  
foo();
 
}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 foo() {
  
System.
out
.println(
"B.foo()"
);
 
}
 
public
 
static
 
void
 
main(String
[] args)
{
  
A a = 
new
 B();
  
a.bar();
 
}
}
32
32
ס
ד
ר
 
ה
פ
ע
ו
ל
ו
ת
 
ב
י
צ
י
ר
ת
 
א
ו
ב
י
י
ק
ט
א
ת
ח
ו
ל
 
ע
ר
ך
 
ד
י
פ
ו
ל
ט
י
 
ל
ש
ד
ו
ת
 
מ
ו
פ
ע
.
ק
ר
י
א
ה
 
ל
ב
נ
א
י
 
ש
ל
 
מ
ח
ל
ק
ת
 
ה
א
ב
 
(
ש
ג
ו
ר
ר
 
א
ו
ת
ו
 
ס
ד
ר
 
פ
ע
ו
ל
ו
ת
ר
ק
ו
ר
ס
י
ב
י
ת
)
.
א
ת
ח
ו
ל
 
ש
ד
ו
ת
 
מ
ו
פ
ע
 
ל
פ
י
 
ה
ע
ר
כ
י
ם
 
ש
ה
ו
ש
מ
ו
 
ל
ה
ם
 
ב
ש
ו
ר
ה
 
ש
ב
ה
 
ה
ם
מ
ו
ג
ד
ר
י
ם
.
ב
י
צ
ו
ע
 
ש
א
ר
 
ה
ק
ו
ד
 
ש
ל
 
ה
ב
נ
א
י
.
33
33
ס
ד
ר
 
ה
פ
ע
ו
ל
ו
ת
 
ב
י
צ
י
ר
ת
 
א
ו
ב
י
י
ק
ט
public class 
B
 extends 
A{
 
String 
bar
 = 
“B.bar”
;
 
B() { foo(); }
}
 
B(){
   
bar = null;
   
super();
   
bar = “B.bar”;
   
foo();
 }
ס
ד
ר
 
ה
פ
ע
ו
ל
ו
ת
 
ב
י
צ
י
ר
ת
 
א
ו
ב
י
י
ק
ט
1.
א
ת
ח
ו
ל
 
ע
ר
ך
 
ד
י
פ
ו
ל
ט
י
 
ל
ש
ד
ו
ת
 
מ
ו
פ
ע
.
2.
ק
ר
י
א
ה
 
ל
ב
נ
א
י
 
ש
ל
 
מ
ח
ל
ק
ת
 
ה
א
ב
 
(
ש
ג
ו
ר
ר
א
ו
ת
ו
 
ס
ד
ר
 
פ
ע
ו
ל
ו
ת
 
ר
ק
ו
ר
ס
י
ב
י
ת
)
.
3.
א
ת
ח
ו
ל
 
ש
ד
ו
ת
 
מ
ו
פ
ע
 
ל
פ
י
 
ה
ע
ר
כ
י
ם
ש
ה
ו
ש
מ
ו
 
ל
ה
ם
 
ב
ש
ו
ר
ה
 
ש
ב
ה
 
ה
ם
מ
ו
ג
ד
ר
י
ם
.
4.
ב
י
צ
ו
ע
 
ש
א
ר
 
ה
ק
ו
ד
 
ש
ל
 
ה
ב
נ
א
י
.
34
34
ה
ו
ר
ש
ה
 
ו
ב
נ
א
י
ם
public
 
class
 A {
 
String 
bar
 = 
"A.bar"
;
 
 
A() { foo(); }
 
 
public
 
void
 foo() {
  
System.
out
.println(
"A.foo(): bar = "
 +
bar
);
 
}
}
 
public
 
class
 B 
extends
 A {
 
String 
bar
 = 
"B.bar"
;
 
 
B() { foo(); }
 
 
public
 
void
 foo() {
  
System.
out
.println(
"B.foo(): bar = "
 +
bar
);
 
}
}
public
 
class
 C {
 
public
 
static
 
void
 main(String[]
args) {
  
A a = 
new
 B();
  
System.
out
.println(
"a.bar = "
 + a.
bar
);
  
a.foo();
 
}
}
מ
ה
 
פ
ל
ט
 
ה
ת
ו
כ
נ
י
ת
?
35
35
ה
ו
ר
ש
ה
 
ו
ב
נ
א
י
ם
public
 
class
 A {
 
String 
bar
 = 
"A.bar"
;
 
 
A() { foo(); }
 
 
public
 
void
 foo() {
  
System.
out
.println(
"A.foo(): bar = "
 +
bar
);
 
}
}
 
public
 
class
 B 
extends
 A {
 
String 
bar
 = 
"B.bar"
;
 
 
B() { foo(); }
 
 
public
 
void
 foo() {
  
System.
out
.println(
"B.foo(): bar = "
 +
bar
);
 
}
}
public
 
class
 C {
 
public
 
static
 
void
 main(String[]
args) {
  
A a = 
new
 B();
  
System.
out
.println(
"a.bar = "
 + a.
bar
);
  
a.foo();
 
}
}
W
h
a
t
 
i
s
 
t
h
e
 
o
u
t
p
u
t
?
B.foo(): bar = null
B.foo(): bar = B.bar
a.bar = A.bar
B.foo(): bar = B.bar
מ
ה
 
פ
ל
ט
 
ה
ת
ו
כ
נ
י
ת
?
36
36
ה
ו
ר
ש
ה
 
ו
ב
נ
א
י
ם
 
(
2
)
public
 
class
 A { 
 
protected
 B 
b
 = 
new
 B();    
 
public
 A() { System.
out
.println(
"in A: no args."
); }
 
public
 A(String s) { System.
out
.println(
"in A: s = "
 + s); } 
}
 
public
 
class
 B { 
 
public
 B() { System.
out
.println(
"in B: no args."
); }
} 
 
public
 
class
 C 
extends
 A { 
 
protected
 B 
b
;
 
public
 C() { System.
out
.println(
"in C: no args."
); }
 
public
 C(String s) { System.
out
.println(
"in C: s = "
 + s); } 
}
  
public
 
class
 D {
 
public
 
static
 
void
 main(String args[]) { 
  
C c = 
new
 C(); 
  
A a = 
new
 C();
 
}
}
W
h
a
t
 
i
s
 
t
h
e
 
o
u
t
p
u
t
?
A
B
C
37
37
ה
ו
ר
ש
ה
 
ו
ב
נ
א
י
ם
 
(
2
)
public
 
class
 A { 
 
protected
 B 
b
 = 
new
 B();    
 
public
 A() { System.
out
.println(
"in A: no args."
); }
 
public
 A(String s) { System.
out
.println(
"in A: s = "
 + s); } 
}
 
public
 
class
 B { 
 
public
 B() { System.
out
.println(
"in B: no args."
); }
} 
 
public
 
class
 C 
extends
 A { 
 
protected
 B 
b
;
 
public
 C() { System.
out
.println(
"in C: no args."
); }
 
public
 C(String s) { System.
out
.println(
"in C: s = "
 + s); } 
}
  
public
 
class
 D {
 
public
 
static
 
void
 main(String args[]) { 
  
C c = 
new
 C(); 
  
A a = 
new
 C();
 
}
}
W
h
a
t
 
i
s
 
t
h
e
 
o
u
t
p
u
t
?
ה
פ
ל
ט
:
i
n
 
B
:
 
n
o
 
a
r
g
s
.
i
n
 
A
:
 
n
o
 
a
r
g
s
.
i
n
 
C
:
 
n
o
 
a
r
g
s
.
i
n
 
B
:
 
n
o
 
a
r
g
s
.
i
n
 
A
:
 
n
o
 
a
r
g
s
.
i
n
 
C
:
 
n
o
 
a
r
g
s
.
A
B
C
38
38
ה
ו
ר
ש
ה
 
ו
ב
נ
א
י
ם
 
(
3
)
public
 
class
 A { 
 
protected
 B 
b
 = 
new
 B();    
 
public
 A() { System.
out
.println(
"in A: no args."
); }
 
public
 A(String s) { System.
out
.println(
"in A: s = "
 + s); } 
}
 
public
 
class
 B { 
 
public
 B() { System.
out
.println(
"in B: no args."
); }
} 
 
public
 
class
 C 
extends
 A { 
 
protected
 B 
b
;
 
public
 C() { System.
out
.println(
"in C: no args."
); }
 
public
 C(String s) { System.
out
.println(
"in C: s = "
 + s); } 
}
  
public
 
class
 D {
 
public
 
static
 
void
 main(String args[]) { 
  
C c = 
new
 C(
"c"
); 
  
A a = 
new
 C(
"
a"
);
 
}
}
W
h
a
t
 
i
s
 
t
h
e
 
o
u
t
p
u
t
?
39
39
ה
ו
ר
ש
ה
 
ו
ב
נ
א
י
ם
 
(
3
)
public
 
class
 A { 
 
protected
 B 
b
 = 
new
 B();    
 
public
 A() { System.
out
.println(
"in A: no args."
); }
 
public
 A(String s) { System.
out
.println(
"in A: s = "
 + s); } 
}
 
public
 
class
 B { 
 
public
 B() { System.
out
.println(
"in B: no args."
); }
} 
 
public
 
class
 C 
extends
 A { 
 
protected
 B 
b
;
 
public
 C() { System.
out
.println(
"in C: no args."
); }
 
public
 C(String s) { System.
out
.println(
"in C: s = "
 + s); } 
}
  
public
 
class
 D {
 
public
 
static
 
void
 main(String args[]) { 
  
C c = 
new
 C(
"c"
); 
  
A a = 
new
 C(
"
a"
);
 
}
}
W
h
a
t
 
i
s
 
t
h
e
 
o
u
t
p
u
t
?
ה
פ
ל
ט
:
i
n
 
B
:
 
n
o
 
a
r
g
s
.
i
n
 
A
:
 
n
o
 
a
r
g
s
.
i
n
 
C
:
 
s
 
=
 
c
i
n
 
B
:
 
n
o
 
a
r
g
s
.
i
n
 
A
:
 
n
o
 
a
r
g
s
.
i
n
 
C
:
 
s
 
=
 
a
40
40
ד
ר
י
ס
ה
 
ו
ה
ע
מ
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
public class
 
A {
 
public
 
float
 foo(
float
 a, 
float
 b) 
throws
 IOException {
 
}
}
public
 
class
 B 
extends
 A {
 
}
א
י
ל
ו
 
מ
ה
ש
י
ר
ו
ת
י
ם
 
ה
ב
א
י
ם
 
נ
י
ת
ן
 
ל
ה
ג
ד
י
ר
 
ב
-
 
B
?
1. 
float
 
foo(
float
 a,
 
float
 b){…}
2. 
public
 
int
 foo(
int
 a, 
int
 b) 
throws
 Exception{…}
3. 
public
 
float
 foo(
float
 
a, 
float
 b) 
throws
 
Exception{…}
4. 
public
 
float
 foo(
float
 p, 
float
 q) {…}
41
41
ד
ר
י
ס
ה
 
ו
ה
ע
מ
ס
ה
 
ש
ל
 
ש
י
ר
ו
ת
י
ם
public class
 
A {
 
public
 
float
 foo(
float
 a, 
float
 b) 
throws
 IOException {
 
}
}
public
 
class
 B 
extends
 A {
 
}
א
י
ל
ו
 
מ
ה
ש
י
ר
ו
ת
י
ם
 
ה
ב
א
י
ם
 
נ
י
ת
ן
 
ל
ה
ג
ד
י
ר
 
ב
-
 
B
?
1. 
float
 
foo(
float
 a,
 
float
 b){…}
2. 
public
 
int
 foo(
int
 a, 
int
 b) 
throws
 Exception{…}
3. 
public
 
float
 foo(
float
 
a, 
float
 b) 
throws
 
Exception{…}
4. 
public
 
float
 foo(
float
 p, 
float
 q) {…}
 
 
 
 
42
42
ה
ו
ר
ש
ה
 
ו
ד
ר
י
ס
ת
 
ש
י
ר
ו
ת
י
ם
public class
 
A {
 
public
 
void
 foo() {…}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 foo() {…}
}
ה
א
ם
 
א
פ
ש
ר
 
ל
ק
ר
ו
א
 
ל
-
f
o
o
 
ש
ל
A
 
מ
ת
ו
ך
 
B
?
ת
ש
ו
ב
ה
:
ד
ר
ך
 
s
u
p
e
r
.
f
o
o
(
)
43
43
ה
ו
ר
ש
ה
 
ו
ד
ר
י
ס
ת
 
ש
י
ר
ו
ת
י
ם
 
(
2
)
public class
 
A {
 
public
 
void
 foo() {…}
}
public
 
class
 B 
extends
 A {
 
public
 
void
 foo() {…}
}
public
 
class
 C 
extends
 B {
 
public
 
void
 foo() {…}
}
ה
א
ם
 
א
פ
ש
ר
 
ל
ק
ר
ו
א
 
ל
-
f
o
o
 
ש
ל
A
 
מ
ת
ו
ך
 
C
?
ת
ש
ו
ב
ה
:
א
י
 
א
פ
ש
ר
,
s
u
p
e
r
.
s
u
p
e
r
.
f
o
o
(
)
-
 
ל
א
 
ח
ו
ק
י
44
44
מ
ח
ל
ק
ו
ת
 
פ
נ
י
מ
י
ו
ת
public class
 
Test {
 
public
 
int
 a = 0;
 
private
 
int
 b = 1;
 
public
 
void
 foo(
final
 
int
 c) {
  
int
 
d = 2;
        
 
  
class
 InnerTest {
   
private
 
void
 bar(
int
 e) {
  
            
 
   
}
  
}
  
d = 3;
  
a = 3;
 
}
}
 
א
י
ל
ו
 
מ
ש
ת
נ
י
ם
 
מ
-
 
a
-
e
 
נ
ג
י
ש
י
ם
 
מ
ה
ש
ו
ר
ה
ה
מ
ס
ו
מ
נ
ת
?
45
45
ת
ש
ו
ב
ה
:
 
כ
ו
ל
ם
 
ח
ו
ץ
 
מ
-
d
מ
ח
ל
ק
ו
ת
 
פ
נ
י
מ
י
ו
ת
public class
 
Test {
 
public
 
int
 a = 0;
 
private
 
int
 b = 1;
 
public
 
void
 foo(
final
 
int
 c) {
  
int
 
d = 2;
        
 
  
class
 InnerTest {
   
private
 
void
 bar(
int
 e) {
  
            
 
   
}
  
}
  
d = 3;
  
a = 3;
 
}
}
 
א
י
ל
ו
 
מ
ש
ת
נ
י
ם
 
מ
-
 
a
-
e
 
נ
ג
י
ש
י
ם
 
מ
ה
ש
ו
ר
ה
ה
מ
ס
ו
מ
נ
ת
?
מ
ח
ל
ק
ו
ת
 
פ
נ
י
מ
י
ו
ת
 
-
 
ס
י
כ
ו
ם
46
46
e
n
u
m
47
47
f
i
x
e
d
 
s
e
t
 
o
f
 
c
o
n
s
t
a
n
t
s
A
l
l
 
e
n
u
m
s
 
i
m
p
l
i
c
i
t
l
y
e
x
t
e
n
d
 
j
a
v
a
.
l
a
n
g
.
E
n
u
m
A
n
 
e
n
u
m
 
c
a
n
n
o
t
e
x
t
e
n
d
 
a
n
y
t
h
i
n
g
 
e
l
s
e
.
T
h
e
 
c
o
n
s
t
r
u
c
t
o
r
 
f
o
r
 
a
n
e
n
u
m
 
t
y
p
e
 
i
s
 
a
l
w
a
y
s
p
r
i
v
a
t
e
 
i
m
p
l
i
c
i
t
l
y
.
 
Y
o
u
c
a
n
n
o
t
 
i
n
v
o
k
e
 
a
n
e
n
u
m
 
c
o
n
s
t
r
u
c
t
o
r
y
o
u
r
s
e
l
f
.
e
n
u
m
48
48
s
t
a
t
i
c
 
v
a
l
u
e
s
 
m
e
t
h
o
d
t
h
a
t
 
r
e
t
u
r
n
s
 
a
n
 
a
r
r
a
y
c
o
n
t
a
i
n
i
n
g
 
a
l
l
 
o
f
 
t
h
e
v
a
l
u
e
s
 
o
f
 
t
h
e
 
e
n
u
m
 
i
n
t
h
e
 
o
r
d
e
r
 
t
h
e
y
 
a
r
e
d
e
c
l
a
r
e
d
O
u
t
p
u
t
:
M
o
n
d
a
y
s
 
a
r
e
 
b
a
d
.
S
U
N
D
A
Y
M
O
N
D
A
Y
T
U
E
S
D
A
Y
W
E
D
N
E
S
D
A
Y
T
H
U
R
S
D
A
Y
F
R
I
D
A
Y
S
A
T
U
R
D
A
Y
א
ו
ס
פ
י
ם
 
ג
נ
ר
י
י
ם
49
49
נ
י
ת
ן
 
(
ו
א
פ
י
ל
ו
 
ר
צ
ו
י
)
 
ל
כ
ת
ו
ב
 
ג
ם
:
n
e
w
 
H
a
s
h
S
e
t
<
>
(
)
;
א
ו
ס
פ
י
ם
 
ג
נ
ר
י
י
ם
50
50
ה
א
ם
 
א
נ
ח
נ
ו
 
ח
י
י
ב
י
ם
 
ל
ה
צ
ה
י
ר
 
ע
ל
 
ט
י
פ
ו
ס
 
ס
ט
ט
י
 
ש
ה
ו
א
 
H
a
s
h
S
e
t
?
ב
ד
"
כ
 
נ
ש
ת
מ
ש
 
ב
ט
י
פ
ו
ס
 
ה
כ
ל
ל
י
 
י
ו
ת
ר
 
S
e
t
 
א
ל
א
 
א
ם
 
כ
ן
 
א
נ
ח
נ
ו
נ
ד
ר
ש
י
ם
 
ס
פ
צ
י
פ
י
ת
 
ל
 
H
a
s
h
S
e
t
.
 
ל
מ
ש
ל
 
ב
מ
ק
ר
י
ם
 
ה
ב
א
י
ם
:
1.
א
נ
ח
נ
ו
 
ר
ו
צ
י
ם
 
ל
ה
פ
ע
י
ל
 
מ
ת
ו
ד
ה
 
ש
י
ש
 
ל
 
H
a
s
h
S
e
t
 
א
ך
 
ל
א
 
ל
S
e
t
 
(
י
ש
 
כ
ז
ו
 
ב
כ
ל
ל
?
)
2.
א
נ
ח
נ
ו
 
מ
ש
ת
מ
ש
י
ם
 
ב
ש
י
ר
ו
ת
 
ש
ד
ו
ר
ש
 
ל
ק
ב
ל
 
ר
ק
 
H
a
s
h
S
e
t
ו
ל
א
 
S
e
t
.
א
ו
ס
פ
י
ם
 
ג
נ
ר
י
י
ם
51
51
מ
ד
ו
ע
 
ה
פ
ו
נ
ק
צ
י
ה
 
ד
ו
ר
ש
ת
 
ל
ק
ב
ל
 
H
a
s
h
S
e
t
?
 
ב
ד
"
כ
 
נ
ש
ת
מ
ש
ב
ט
י
פ
ו
ס
 
כ
מ
ה
 
ש
י
ו
ת
ר
 
כ
ל
ל
י
.
 
ה
א
ם
 
נ
ו
כ
ל
 
ל
ש
ל
ו
ח
 
ל
פ
ה
 
כ
ל
 
S
e
t
?
ע
"
מ
 
ה
מ
י
מ
ו
ש
 
ש
ל
ה
,
 
א
י
ן
 
ס
י
ב
ה
 
ש
ל
א
.
 
ל
מ
ע
ן
 
ה
א
מ
ת
,
 
נ
ו
כ
ל
 
ל
ש
ל
ו
ח
א
פ
י
ל
ו
 
C
o
l
l
e
c
t
i
o
n
.
א
ו
ס
פ
י
ם
 
ג
נ
ר
י
י
ם
52
52
ה
א
ם
 
י
ש
 
ע
ו
ד
 
מ
ש
ה
ו
 
ש
נ
ו
כ
ל
 
ל
ש
פ
ר
 
ב
ק
ו
ד
?
נ
ש
י
ם
 
ל
ב
 
כ
י
 
ה
מ
י
מ
ו
ש
 
ש
ל
 
f
u
n
c
 
ל
א
 
מ
ח
י
י
ב
 
א
ו
ת
נ
ו
 
ל
ק
ב
ל
 
א
ו
ס
ף
 
ש
ל
מ
ח
ר
ו
ז
ו
ת
.
 
ה
ד
ר
י
ש
ה
 
ה
י
ח
י
ד
ה
 
ה
י
א
 
ש
א
ב
ר
י
 
ה
א
ו
ס
ף
 
י
מ
מ
ש
ו
 
א
ת
t
o
S
t
r
i
n
g
,
 
מ
ה
 
ש
מ
ו
ב
ט
ח
 
ל
כ
ל
 
א
ו
ב
י
י
ק
ט
 
ב
 
J
a
v
a
.
א
ו
ס
פ
י
ם
 
ג
נ
ר
י
י
ם
53
53
נ
ש
ת
מ
ש
 
ב
 
<
?
>
 
ע
"
מ
 
ל
א
פ
ש
ר
 
ש
י
מ
ו
ש
 
ב
א
ו
ס
פ
י
ם
 
ש
ל
 
כ
ל
 
ט
י
פ
ו
ס
א
פ
ש
ר
י
.
ש
י
מ
ו
 
ל
ב
,
 
ל
ה
ג
ד
י
ר
 
א
ת
 
s
e
t
 
מ
ט
י
פ
ו
ס
 
C
o
l
l
e
c
t
i
o
n
<
O
b
j
e
c
t
>
 
ל
א
י
ש
י
ג
 
א
ת
 
א
ו
ת
ה
 
ה
מ
ט
ר
ה
,
 
כ
י
ו
ו
ן
 
ש
א
ז
 
נ
ו
כ
ל
 
ל
ה
פ
ע
י
ל
 
א
ת
 
ה
פ
ו
נ
ק
צ
י
ה
ה
ז
ו
 
ר
ק
 
ע
ם
 
א
ו
ב
י
י
ק
ט
 
מ
ט
י
פ
ו
ס
 
ס
ט
ט
י
 
C
o
l
l
e
c
t
i
o
n
<
O
b
j
e
c
t
>
א
ו
ס
פ
י
ם
 
ג
נ
ר
י
י
ם
54
54
נ
ש
ת
מ
ש
 
ב
 
<
?
>
 
ע
"
מ
 
ל
א
פ
ש
ר
 
ש
י
מ
ו
ש
 
ב
א
ו
ס
פ
י
ם
 
ש
ל
 
כ
ל
 
ט
י
פ
ו
ס
א
פ
ש
ר
י
.
ש
י
מ
ו
 
ל
ב
,
 
ל
ה
ג
ד
י
ר
 
א
ת
 
s
e
t
 
מ
ט
י
פ
ו
ס
 
C
o
l
l
e
c
t
i
o
n
<
O
b
j
e
c
t
>
 
ל
א
י
ש
י
ג
 
א
ת
 
א
ו
ת
ה
 
ה
מ
ט
ר
ה
,
 
כ
י
ו
ו
ן
 
ש
א
ז
 
נ
ו
כ
ל
 
ל
ה
פ
ע
י
ל
 
א
ת
 
ה
פ
ו
נ
ק
צ
י
ה
ה
ז
ו
 
ר
ק
 
ע
ם
 
א
ו
ב
י
י
ק
ט
 
מ
ט
י
פ
ו
ס
 
ס
ט
ט
י
 
C
o
l
l
e
c
t
i
o
n
<
O
b
j
e
c
t
>
א
ו
ס
פ
י
ם
 
ג
נ
ר
י
י
ם
 
55
55
Slide Note
Embed
Share

In this content, we explore Java interface modifiers, class hierarchy, and exception handling. The examples illustrate concepts like abstract methods, interface implementation, and class extension. Learn about the relationships between Animal, Dog, Poodle, and Labrador classes in Java programming. Understand the scenarios where exceptions are thrown and how they are handled.

  • Java Programming
  • Interface Modifiers
  • Class Hierarchy
  • Exception Handling
  • Animal Classes

Uploaded on Feb 23, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. 1 1 12 : Summery 1

  2. 2 ! :

  3. 3 : java 9 ) - , ( public interface MyInterface { public abstract int foo1(int i); int foo2(int i); } The modifiers of foo1 and foo2 are the same.

  4. 4 public interface Foo { public void bar() throws Exception; } public class FooImpl implements Foo { public void bar() { System.out.println("No exception is thrown"); } public static void main(String args[]) { Foo foo = new FooImpl(); foo.bar(); } ? ? ? ? , ? , , , }

  5. 5 public interface Foo { public void bar() throws Exception; } public class FooImpl implements Foo { public void bar() { System.out.println("No exception is thrown"); } public static void main(String args[]) { Foo foo = new FooImpl(); foo.bar(); } } : "Unhandled exception type Exception"

  6. 6 - public interface Foo { public void bar() throws Exception; } public class FooImpl implements Foo { public void bar() { System.out.println("No exception is thrown"); } public static void main(String args[]) { FooImpl foo = new FooImpl(); foo.bar(); } ? ? ? ? , ? , , , }

  7. 7 - public interface Foo { public void bar() throws Exception; } public class FooImpl implements Foo { public void bar() { System.out.println("No exception is thrown"); } public static void main(String args[]) { FooImpl foo = new FooImpl(); foo.bar(); } } : "No exception is thrown"

  8. 8 Consider the following class hierarchy: Animal Interface Animal { } class Dog implements Animal{ } class Poodle extends Dog { } class Labrador extends Dog { } Dog Poodle Labrador Which of the following lines (if any) will not compile? Poodle poodle = new Poodle(); Animal animal = (Animal) poodle; Dog dog = new Labrador(); animal = dog; poodle = dog;

  9. 9 Consider the following class hierarchy: Animal Interface Animal { } class Dog implements Animal{ } class Poodle extends Dog { } class Labrador extends Dog { } Dog Poodle Labrador Which of the following lines (if any) will not compile? poodle = (Poodle) dog; Poodle poodle = new Poodle(); Animal animal = (Animal) poodle; Dog dog = new Labrador(); animal = dog; poodle = dog; Type mismatch: cannot convert from Dog to Poodle -No compilation error -Runtime Exception - Compilation Error Labrador labrador = (Labrador) dog; -No compilation error -No Runtime Exception

  10. 10 class A { public void print() { System.out.println("A"); } } ? class B extends A implements C { } interface C { void print(); }

  11. 11 class A { public void print() { System.out.println("A"); } } class B extends A implements C { } interface C { void print(); } public

  12. 12 class A { void print() { System.out.println("A"); } ? } class B extends A implements C { } interface C { void print(); }

  13. 13 class A { void print() { System.out.println("A"); } } class B extends A implements C { } : interface C { void print(); } The inherited package method A.print() cannot hide the public abstract method in C

  14. 14 The following table shows the access to members permitted by each modifier Access Level Modifier public protected No modifier private Class Y Y Y Y Package Y Y Y N Subclass Y Y N N World Y N N N default https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

  15. 15 public class A { public void print() { System.out.println("A"); } } public class C { public static void main(String[] args){ B b = new B(); A a = b; b.print(); a.print(); public class B extends A { public void print() { System.out.println("B"); } } } } ? ? ? ? , ? , , ,

  16. 16 public class A { public void print() { System.out.println("A"); } } public class C { public static void main(String[] args){ B b = new B(); A a = b; - casting b.print(); a.print(); public class B extends A { public void print() { System.out.println("B"); } } } } : ? ? ? ? , B B ? , , ,

  17. 17 public class A { public void print() { System.out.println("A"); } } public class C { public static void main(String[] args) { B b = new B(); b.print(); } public class B extends A { protected void print() { System.out.println("B"); } } } ? ? ? ? , ? , , ,

  18. 18 public class A { public void print() { System.out.println("A"); } } public class C { public static void main(String[] args) { B b = new B(); b.print(); } public class B extends A { protected void print() { System.out.println("B"); } } } "Cannot reduce the visibility of the inherited method from A" : ? ? ? ? , ? , , ,

  19. 19 ( 2 ) public class A { protected void print() { System.out.println("A"); } } public class C { public static void main(String[] args) { B b = new B(); b.print(); } public class B extends A { public void print() { System.out.println("B"); } } } ? ? ? ? , ? , , ,

  20. 20 ( 2 ) public class A { protected void print() { System.out.println("A"); } } public class C { public static void main(String[] args) { B b = new B(); b.print(); } public class B extends A { public void print() { System.out.println("B"); } } } ? ? ? ? , : ? , , , B

  21. 21 ( 3 ) public class A { public void foo() { System.out.println("A"); } } public class B extends A { public static void foo() { System.out.println("B"); } } public class BindingTest { public static void main(String args[]) { B b = new B(); b.foo(); } } ? , ? ? ,

  22. 22 ( 3 ) public class A { public void foo() { System.out.println("A"); } } Compilation Error: foo() in B cannot override foo() in A. overriding method is static. public class B extends A { public static void foo() { System.out.println("B"); } } public class BindingTest { public static void main(String args[]) { B b = new B(); b.foo(); } } ? , ? ? ,

  23. 23 ( 4 ) public class A { public static void foo() { System.out.println("A"); } } public class B extends A { public void foo() { System.out.println("B"); } } public class BindingTest { public static void main(String args[]) { B b = new B(); b.foo(); } } ? , ? ? ,

  24. 24 ( 4 ) public class A { public static void foo() { System.out.println("A"); } } Compilation Error: foo() in B cannot override foo() in A. overridden method is static. public class B extends A { public void foo() { System.out.println("B"); } } public class BindingTest { public static void main(String args[]) { B b = new B(); b.foo(); } } ? , ? ? ,

  25. 25 ( 5 ) public class A { private static void foo() { System.out.println("A"); } } public class B extends A { public void foo() { System.out.println("B"); } } public class BindingTest { public static void main(String args[]) { B b = new B(); b.foo(); } } ? , ? ? ,

  26. 26 ( 5 ) public class A { private static void foo() { System.out.println("A"); } } Output: public class B extends A { public void foo() { System.out.println("B"); } B } public class BindingTest { public static void main(String args[]) { B b = new B(); b.foo(); } } ? , ? ? ,

  27. 27 Static binding (or early binding) Static binding: bind at compilation time Performed if the compiler can resolve the binding at compile time Applied for Static methods Private methods Final methods Fields

  28. 28 Binding public class B extends A { public void foo() { System.out.println("B.foo()"); } public class A { public void foo() { System.out.println("A.foo()"); } public void bar() { System.out.println("A.bar()"); foo(); } public static void main(String[] args) { A a = new B(); a.bar(); } } } ? ? ? ? , ? , , ,

  29. 29 Binding public class B extends A { public void foo() { System.out.println("B.foo()"); } public class A { public void foo() { System.out.println("A.foo()"); } public void bar() { System.out.println("A.bar()"); foo(); } public static void main(String[] args) { A a = new B(); a.bar(); } } } : ? ? ? ? , A.bar() B.foo() ? , , ,

  30. 30 Binding (2) public class B extends A { public void foo() { System.out.println("B.foo()"); } public class A { private void foo() { System.out.println("A.foo()"); } public void bar() { System.out.println("A.bar()"); foo(); } public static void main(String[] args) { A a = new B(); a.bar(); } } } ? ? ? ? , ? , , ,

  31. 31 Binding (2) public class B extends A { public void foo() { System.out.println("B.foo()"); } public class A { private void foo() { System.out.println("A.foo()"); } public void bar() { System.out.println("A.bar()"); foo(); } public static void main(String[] args) { A a = new B(); a.bar(); } } } ? ? ? ? , : ? , , , A.bar() A.foo()

  32. 32 . ( .) . .

  33. public class B extends A{ String bar = B.bar ; B() { foo(); } } B(){ bar = null; super(); bar = B.bar ; foo(); } . ( .) .1 .2 .3 . .4 . 33

  34. 34 public class A { String bar = "A.bar"; public class C { public static void main(String[] args) { A a = new B(); System.out.println("a.bar = " + a.bar); a.foo(); } } A() { foo(); } public void foo() { System.out.println("A.foo(): bar = " + bar); } } public class B extends A { String bar = "B.bar"; ? B() { foo(); } public void foo() { System.out.println("B.foo(): bar = " + bar); } }

  35. 35 public class A { String bar = "A.bar"; public class C { public static void main(String[] args) { A a = new B(); System.out.println("a.bar = " + a.bar); a.foo(); } } A() { foo(); } public void foo() { System.out.println("A.foo(): bar = " + bar); } } public class B extends A { String bar = "B.bar"; ? B() { foo(); } What is the output? B.foo(): bar = null B.foo(): bar = B.bar a.bar = A.bar B.foo(): bar = B.bar public void foo() { System.out.println("B.foo(): bar = " + bar); } }

  36. 36 ( 2 ) public class A { protected B b = new B(); public A() { System.out.println("in A: no args."); } public A(String s) { System.out.println("in A: s = " + s); } } What is the output? A public class B { public B() { System.out.println("in B: no args."); } } B public class C extends A { protected B b; public C() { System.out.println("in C: no args."); } public C(String s) { System.out.println("in C: s = " + s); } } C public class D { public static void main(String args[]) { C c = new C(); A a = new C(); } }

  37. 37 ( 2 ) public class A { protected B b = new B(); public A() { System.out.println("in A: no args."); } public A(String s) { System.out.println("in A: s = " + s); } } What is the output? : A in B: no args. in A: no args. in C: no args. in B: no args. in A: no args. in C: no args. public class B { public B() { System.out.println("in B: no args."); } } B public class C extends A { protected B b; public C() { System.out.println("in C: no args."); } public C(String s) { System.out.println("in C: s = " + s); } } C public class D { public static void main(String args[]) { C c = new C(); A a = new C(); } }

  38. 38 ( 3 ) public class A { protected B b = new B(); public A() { System.out.println("in A: no args."); } public A(String s) { System.out.println("in A: s = " + s); } } What is the output? public class B { public B() { System.out.println("in B: no args."); } } public class C extends A { protected B b; public C() { System.out.println("in C: no args."); } public C(String s) { System.out.println("in C: s = " + s); } } public class D { public static void main(String args[]) { C c = new C("c"); A a = new C("a"); } }

  39. 39 ( 3 ) public class A { protected B b = new B(); public A() { System.out.println("in A: no args."); } public A(String s) { System.out.println("in A: s = " + s); } } What is the output? : in B: no args. in A: no args. in C: s = c in B: no args. in A: no args. in C: s = a public class B { public B() { System.out.println("in B: no args."); } } public class C extends A { protected B b; public C() { System.out.println("in C: no args."); } public C(String s) { System.out.println("in C: s = " + s); } } public class D { public static void main(String args[]) { C c = new C("c"); A a = new C("a"); } }

  40. 40 public class A { public float foo(float a, float b) throws IOException { } } public class B extends A { } B ? - 1. float foo(float a, float b){ } 2. public int foo(int a, int b) throws Exception{ } 3. public float foo(float a, float b) throws Exception{ } 4. public float foo(float p, float q) { }

  41. 41 public class A { public float foo(float a, float b) throws IOException { } } public class B extends A { } B ? - 1. float foo(float a, float b){ } 2. public int foo(int a, int b) throws Exception{ } 3. public float foo(float a, float b) throws Exception{ } 4. public float foo(float p, float q) { }

  42. 42 public class A { public void foo() { } } foo - B ? A : super.foo() public class B extends A { public void foo() { } }

  43. 43 ( 2 ) public class A { public void foo() { } } foo - C ? A , : public class B extends A { public void foo() { } } super.super.foo() - public class C extends B { public void foo() { } }

  44. 44 public class Test { public int a = 0; private int b = 1; a-e - ? public void foo(final int c) { int d = 2; class InnerTest { private void bar(int e) { } } d = 3; a = 3; } }

  45. 45 public class Test { public int a = 0; private int b = 1; a-e - ? public void foo(final int c) { int d = 2; - d : class InnerTest { private void bar(int e) { } } d = 3; a = 3; } }

  46. 46 - Type Construct Interface Fields access Anywhere yes Only static Static nested Anywhere, From outer class member Local scope (only in the function it was declared) Only the point where it is defined no Static and non-static Inner non- static no Effectively final local variables or parameters that are accessible in the scope of the block Effectively final local variables or parameters that are accessible in the scope of the block local no anonymous

  47. 47 enum All enums implicitly extend java.lang.Enum An enum cannot extend anything else. The constructor for an enum type is always private implicitly. You cannot invoke an enum constructor yourself. fixed set of constants

  48. 48 enum Output: Mondays are bad. SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY static values method that returns an array containing all of the values of the enum in the order they are declared

  49. 49 : new HashSet<>(); ) (

  50. 50 HashSet Set HashSet . : HashSet ? " .1 Set ? ) ( HashSet .2 Set .

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#