How should you call the Glass class implementation of the break() method?

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?

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?

A.
Window.break();

B.
Glass.break();

C.
this.break();

D.
base.break();



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Christian Zalto

Christian Zalto

Should be C: this.break();

R

R

I think B is correct. Because you are going to call the Glass class. Not call the break function inside Glass.

SirIsaac007

SirIsaac007

The Correct answer is C. this.break();
because method break() are inherited from Windows class which is the base..

CMIIW..

eucledio

eucledio

Tested:
public class Window
{
protected int Break()
{
return 0;
}
}
public class Glass :Window

{
public void foo() {
this.Break();
}

}

Answer: this.Break();

Arnold

Arnold

Answer: this.Break();

“Glass.break()” Would be for a static method.

DB7

DB7

Depends from where called (mind you, questions states ‘how would you call the Glass implementation of the Break method’, not how would you implement it within Glass class).
Either way…
From Glass class = this.Break
From Glass instance = cGlass.Break (Glass.Break is static syntax)

Questions are hard to decipher, …as are the answer options???