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 8

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


rao

rao

third box is:
((Logger)logger).LogCompleted();

Riccardo

Riccardo

Correct!!! I tested this:

BaseLogger logger = new Logger();
logger.Log(“Log started”);
logger.Log(“Base: Log continuing”);
((Logger)logger).LogCompleted(); // Display ‘Finished’

BaseLogger logger = new Logger();
logger.Log(“Log started”);
logger.Log(“Base: Log continuing”);
logger.LogCompleted(); // Display ‘Completed’

Developer

Developer

Answer is correct. no other other option gives expected result.

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

abstract class BaseLogger
{
public virtual void Log(string message)
{
Console.WriteLine(“Base: ” + message);
}

public virtual void LogCompleted()
{
Console.WriteLine(“Completed”);
}
}

class Logger : BaseLogger
{
public override void Log(string message)
{
Console.WriteLine(message);
}

public override void LogCompleted()
{
Console.WriteLine(“Finished”);
}
}

rao

rao

ok, confirmed.
The code run as expected

thanks

Elvis

Elvis

Your implentation is not same as in the qustion. Instead “override LogCompleted()” in the question is “new LogCompleted()”, so last box must be cast in the Logger before invoke the method LogCompleted() , only so the result is right . Point thing is in the keyword “new” .

fabrizio

fabrizio

this is working too:

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

Susantha

Susantha

This is correct
@Riccardo

BaseLogger logger = new Logger();
logger.Log(“Log started”);
logger.Log(“Base: Log continuing”);
((Logger)logger).LogCompleted(); // Display ‘Finished’

BaseLogger logger = new Logger();
logger.Log(“Log started”);
logger.Log(“Base: Log continuing”);
logger.LogCompleted(); // Display ‘Completed’