Arrange calls to the superclass's methods and access modifiers to achieve the following screen output:
C class, method2
A class, method2
A class, method1
B class, method1
1. Only one of the superclass's methods can be called from each method.
2. Only one of the class's methods can be called from e
Making the right conclusion
- 12
Locked
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Hoist
11 August 2024, 19:40
Main Idea: You have 3 classes: A, B, and C. Each class has methods that print messages. The methods in these classes -- call each other --- in a specific order to produce the specific output pattern.
... access / override / inheritance
Output:
C class, method2
A class, method2
A class, method1
B class, method1
// An object of class C is created but referenced as type A
can use it like an A object, but it still has all the features of C
// create an object using the C class model but refer to it as an A type, allowing use
// in a more general way while still having all the specific features of C
Program Flow
Call method2 on the C object:
This starts with C’s method2, which prints “C class, method2”.
Then it calls method1 from B.
B’s method1:
This first calls method2 from A, which prints “A class, method2”.
Then A’s method2 calls its own method1, which prints “A class, method1”.
After that, B’s method1 prints “B class, method1”.
Output printed in order ...
+2
matemate123
13 February 2023, 19:28
First time I see red error in intellij but program run without error.
0
Romain
3 February 2021, 18:17
Why make the class A's method1 private allows to his method2 to call his method1 and not the class C one's ?
+2
Isma Java Developer
17 January 2021, 12:22
This one has to be verified online as Intellij doesn't allow you to compile the code
+1
Mateusz
21 September 2020, 08:49
The only solution acceptable by the verifier won't compile. However, a good solution displaying correct results is not acccepted by the verifier :(
+1
Mayu
18 August 2020, 16:11
I had to verify online for this to work. Intellij had a problem with ambiguous method call
+3