+ 6

Method preference in Inheritance

Consider class A and class B. Let B be a subclass of A. If both the class contain method hello (), then if we call it using an object of B, say b, as b.hello () in the main, which of the methods will be called? Is it the same for C++ and Java?

10th Apr 2017, 2:41 PM
Pixie
Pixie - avatar
1 ответ
+ 4
The method from class B will be called. Class B overrides the 'hello()'-method from class A, beacause they have the same name and parameters (none, in this case). Because object 'b' is an instance of class B, the 'hello()'-method from class B will be called. This is the same for C++.
10th Apr 2017, 3:11 PM
Pim
Актуальное сегодня
.
1 Votes
What?
0 Votes
HTML
0 Votes
Web
0 Votes
Quiz duel
0 Votes
FRC Coding?
1 Votes
help
0 Votes
AI
2 Votes
APIs
1 Votes