You have a class named Glass that inherits from a base class named Window. The Window class includes a protected method named break(). How should you call the Glass class implementation of the break() method?
From the dotnet language specification / classes:
"An override declaration can access the overridden base method using a base_access (Base access). In the example the base.PrintFields() invocation in B invokes the PrintFields method declared in A."
Should be base.break() if you want to explicitly call the parent classes method - this.break() would work but could be overloaded if the base break() method isn't denoted as final.
It should be base.break() because Window inherits from Glass and you should call the Glass class implementation of the break() method. this.break() would call the Window implementation of the break() method. The first two answers are stupid because these would only be valid if the methods were static as the method name is prefixed by the class name and the question states that the methods are 'protected' and the question doesn't contain the keyword 'static'.
And I also read it wrong as I thought Window inherits from Glass (feels logical as windows are made of glass and glasses aren't made of windows) but it's the other way around :)
This keeps being propagated in exam test prep questions. this and base are the C# keywords for accessing the derived and base class implementations. Windows and Glass are the class name. I thought maybe if they were static methods but static cant be virtual. There is another question which uses MyBase and This and a Vehicle/Truck analogy but it to is also wrong.
i'd say base.break(); is the better approach because the question specifically asks for the base class version of the method, and if the method was overridden this.break(); would call the overridden version instead
again i read it wrong.
this.brake() for the Glass implementation (derived class)
base.brake() for the Window implementation (base class)
upvoted 9 times
...
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Django
Highly Voted 3 years, 3 months agoabdaziz
Most Recent 3 weeks, 2 days agoKinC
11 months agoJamieS
7 months, 2 weeks agoseanbourg
11 months, 1 week agooneup
1 year, 2 months agomatt11
11 months, 2 weeks agooneup
1 year, 2 months agospotty
1 year, 4 months agomusado
2 years, 6 months agoHashino
2 years, 4 months agoHashino
2 years, 4 months ago