-
Notifications
You must be signed in to change notification settings - Fork 11
/
Question26.java
57 lines (54 loc) · 1.09 KB
/
Question26.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
55
56
57
package io.github.mariazevedo88.javaoca.chp.three.caelum.operators;
/**
* @author Mariana Azevedo
* @since 29/06/2019
*
* Question 1.3.26 (page 138) - Choose the appropriate option when attempting to compile
* and run the following file:
*
* class B extends C {}
*
* class C {
* int x;
* public boolean equals(C c) {
* return c.x==x;
* }
* }
*
* class A {
* public static void main(String[] args) {
* C a = new C();
* C b = new B();
* a.x = 1;
* b.x = 1;
* System.out.println(a==b);
* System.out.println(a.equals(b));
* }
* }
*
* a) Doesn't compile. (x)
* b) Compiles and prints true, false.
* c) Compiles and prints true, true.
* d) Compiles and prints false, false.
* e) Compiles and prints false, true.
*/
class E extends F {}
class G {
int x;
}
class F {
int x;
//public boolean equals(Object c) {
//return c.x==x;
//}
}
class Question26 {
public static void main(String[] args) {
F a = new F();
//C b = new D();
a.x = 1;
// b.x = 1;
// System.out.println(a==b);
// System.out.println(a.equals(b));
}
}