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?
4/10/2017 2:41:05 PM
Pixie1 Answer
New AnswerThe 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++.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message