Which four lines of code should you use in sequence?

DRAG DROP
You are developing a C# console application that outputs information to the screen. The following
code segments implement the two classes responsible for making calls to the Console object:

When the application is run, the console output must be the following text:
Log started
Base: Log continuing
Finished
You need to ensure that the application outputs the correct text.
Which four lines of code should you use in sequence? (To answer, move the appropriate classes
from the list of classes to the answer area and arrange them in the correct order.)

DRAG DROP
You are developing a C# console application that outputs information to the screen. The following
code segments implement the two classes responsible for making calls to the Console object:

When the application is run, the console output must be the following text:
Log started
Base: Log continuing
Finished
You need to ensure that the application outputs the correct text.
Which four lines of code should you use in sequence? (To answer, move the appropriate classes
from the list of classes to the answer area and arrange them in the correct order.)

Answer: See the explanation

Explanation:
Box 1:

Box 2:

Box 3:

Box 4:

Note:
* The abstract keyword enables you to create classes and class members that are incomplete and
must be implemented in a derived class.
* An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common
definition of a base class that multiple derived classes can share.



Leave a Reply 7

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


Yoelvis

Yoelvis

for Box 4:
logger.LogCompleted(); is not correct since they are using “new” in the method, so the polymorphism does not work in that case.
You should cast it. ((Logger)logger)log.LogCompleted();

sv1slim

sv1slim

BaseLogger logger = new Logger();
logger.Log(“Log started”);
logger.Log(“Base: Log continuing.”);
((Logger)logger).LogCompleted();

Najlepszy Programista Swiata

Najlepszy Programista Swiata

6,5,1,4

SafeHub

SafeHub

((Logger)logger)log.LogCompleted() needs a cast. tested and verified.

Lord Vader

Lord Vader

not following why you need to cast it. new keyword implies you are making a brand new method in the derived class that has nothing to do with any method by the same name in the base class.

Lord Vader

Lord Vader

https://msdn.microsoft.com/en-us/library/ms173153.aspx

these dudes have completely misinterpreted new and confused it with override. the only impact is when you reference a base class instance and execute a virtual () wiht an override implementation in hte subclass.
The override modifier extends the base class method, and the new modifier hides it.

answer is as is givenm

Lord Vader

Lord Vader

i misread this. given answer is wrong on box 4. need an explicit cast.
logger is a reference to type baselogger. to invoke the new () of Logger u need to cast logger to Logger.

((Logger)logger).LogCompleted();