PrepAway - Latest Free Exam Questions & Answers

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.)

PrepAway - Latest Free Exam Questions & Answers

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.

8 Comments on “Which four lines of code should you use in sequence?

    1. Riccardo says:

      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’




      2



      0
  1. Developer says:

    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”);
    }
    }




    1



    1
      1. Elvis says:

        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” .




        1



        0
  2. Susantha says:

    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’




    0



    0

Leave a Reply