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.

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

  1. Maurice says:

    The answer displayed above is correct i tested it myself in visual studio answer is:

    BaseLogger logger = new Logger();

    logger.Log(“Log Started”);

    logger.Log(“Base: Log Continuning”);

    logger.LogCompleted();




    1



    0
  2. JZED says:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication6
    {
    class Program
    {
    static void Main(string[] args)
    {
    BaseLogger logger = new Logger();

    logger.Log(“Log started!”);
    logger.Log(“Base: Log Continuing”);
    ((Logger)logger).LogCompleted();

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

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

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

    }

    }




    0



    0
  3. Elvis says:

    This is the point thing at the keyword new in the method Logger.LogCompleted() that hides method LogCompleted() inherited from BaseLogger class . If would replace the new keyword with override this answer would be true:

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

    In this question we must in this way answer:

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




    0



    0
  4. Guest says:

    The 4th is

    ((Logger)logger).LogCompleted();

    because in the first line, we declared the logger to be a “base logger”. So when we call LogComplete, we automatically call if trom the BaseLogger class, as this is the type of our ‘logger’-variable.

    So ‘logger.LogComplete()’ is short for actually this code:
    ((BaseLogger)logger).LogComplete();




    0



    0
  5. Fydra says:

    6,5,1,7
    BaseLogger logger = new Logger();
    logger.Log(“Log Started”);
    logger.Log(“Base: Log Continuning”);
    logger.LogCompleted();

    Cause “public NEW void Log.Complited”
    With “new” sword logger don`t know about base LogCompleted in BaseLogger class.




    0



    0

Leave a Reply