marinathepichu
Test por , creado hace más de 1 año

Test sobre Quiz 2 [Object-Oriented Programming], creado por marinathepichu el 09/04/2016.

2578
1
0
marinathepichu
Creado por marinathepichu hace más de 8 años
Cerrar

Quiz 2 [Object-Oriented Programming]

Pregunta 1 de 20

1

What are the three main features of object-oriented programming? (pick 3)

Selecciona una o más de las siguientes respuestas posibles:

  • abstraction

  • encapsulation

  • inheritance

  • methods

  • polymorphism

  • recursion

Explicación

Pregunta 2 de 20

1

A(n) _______ is a type that references a method.

Selecciona una de las siguientes respuestas posibles:

  • modifier

  • accessor

  • class

  • delegate

Explicación

Pregunta 3 de 20

1

A class that does not provide a complete implementation must be declared with the keyword _________.

Selecciona una de las siguientes respuestas posibles:

  • abstract

  • static

  • inc

  • delegate

Explicación

Pregunta 4 de 20

1

You are writing a code to handel events in your protram. You define a delegate named RectangleHandler like this:

public delegate void RectangleHandler(Rectangle rect);

you also create a variable of the RectangleHandler type as follows:

RectangleHandler handler;

Later in the program, you need to add a method named DisplayArea to the methodinvocation list of the handler variable. The signature of the DisplayArea method matches the signature of the RectangleHandler method. Any code that you write should not affect any existing event-handling code. Given this restriction, which of the following codes should you write?

Selecciona una de las siguientes respuestas posibles:

  • handler = DisplayArea;

  • handler = new RectangleHandler(DisplayArea);

  • hander -= DisplayArea;

  • handler += DisplayArea;

Explicación

Pregunta 5 de 20

1

A(n) _______ is a blueprint of an object.

Selecciona una de las siguientes respuestas posibles:

  • class

  • method

  • variable

  • flowchart

Explicación

Pregunta 6 de 20

1

You are writing code for a class named Product. You need to make sure that the data members of the class are initialized to their correct values as soon as you create an object of the Product class. The initialization code should be always executed. What should you do?

Selecciona una de las siguientes respuestas posibles:

  • Create a constructor in the Product class to initialize data members.

  • Create an event in the Product class to initialize data members.

  • Create a static property in the Product class to initialize data members.

  • Create a static method in the Product class to initialize data members.

Explicación

Pregunta 7 de 20

1

You want to restrict the access for a method to the containing class or to a class that is derived from the containing class. Which access modifier should you use for this method?

Selecciona una de las siguientes respuestas posibles:

  • protected

  • private

  • internal

  • public

Explicación

Pregunta 8 de 20

1

The _______ keyword refers to the current instance of a class.

Selecciona una de las siguientes respuestas posibles:

  • this

  • that

  • current

  • thing

Explicación

Pregunta 9 de 20

1

You can use ______ to group related classes in order to reduce name collisions.

Selecciona una de las siguientes respuestas posibles:

  • namespace

  • encapsulation

  • struct

  • private

Explicación

Pregunta 10 de 20

1

You defined a class AdvMath that defines advanced mathematical functionality. You plan to make classes that are derived from AdvMath. You do not want the functionality of AdvMath class to be inherited into derived classes. What keyword should you use to define the AdvMath class?

Selecciona una de las siguientes respuestas posibles:

  • private

  • internal

  • abstract

  • sealed

Explicación

Pregunta 11 de 20

1

You are creating a new class named Circle. You write the following code:

class Circle: IComparable
{

public double Radius{ get; set; }

public double GetArea()
{

return Radius*Radius*3.14159

}

public int CompareTo(object obj)
{

// some code will go here...

}

}

Selecciona una de las siguientes respuestas posibles:

  • /************************************************

    public int CompareTo(object obj)
    {

    Circle target = (Circle)obj;
    double diff = this.GetArea() - target.GetArea();
    if(diff ==0)
    return 0;
    else if (diff > 0)
    return 1;
    else return -1;

    }
    /*******************************************************

  • /************************************************

    public int CompareTo(object obj)
    {

    Circle target = (Circle)obj;

    if(this==target)
    return 1;
    else if (diff > 0)
    return -1;
    else return 0;

    }
    /*******************************************************

  • /************************************************

    public int CompareTo(object obj)
    {

    Circle target = (Circle)obj;
    double diff = this.GetArea() - target.GetArea();
    if(diff ==0)
    return 1;
    else if (diff > 0)
    return -1;
    else return 0;

    }
    /*******************************************************

  • /************************************************

    public int CompareTo(object obj)
    {

    Circle target = (Circle)obj;

    if(this==target)
    return 0;
    else if (diff > 0)
    return 1;
    else return -1;

    }
    /*******************************************************

Explicación

Pregunta 12 de 20

1

Which of the following class elements should you use to define the behavior of a class?

Selecciona una de las siguientes respuestas posibles:

  • method

  • event

  • property

  • delegate

Explicación

Pregunta 13 de 20

1

You can use the _____ keyword to declare a member that belongs to the class itself rather than to a specific object.

Selecciona una de las siguientes respuestas posibles:

  • static

  • public

  • private

  • limited

Explicación

Pregunta 14 de 20

1

You can use the ______ operator to check whether it is legal to cast one type to another type.

Selecciona una de las siguientes respuestas posibles:

  • is

  • try

  • castTo

  • =

Explicación

Pregunta 15 de 20

1

INCOMPLETE

The Draw() method in the Square class should provide new functionality but also hide the Polygon class implementation of the Draw() method. Which line of code would accomplish this?

Selecciona una de las siguientes respuestas posibles:

  • INCORRECT

    public static void Draw()

  • INCORRECT

    public virtual void Draw()

  • public new void Draw()

  • public override void Draw()

Explicación

Pregunta 16 de 20

1

INCOMPLETE

You need to provide query functionality to several of your classes. Each class's algorithm for the query will likely be different. Also, not all the classes have an "is-a" relationship with each other. How should you support this functionality?

Selecciona una de las siguientes respuestas posibles:

  • INCORRECT


    Have all the classes inherit from an abstract base class and override the base-class method to provide their own query functionality.

  • Create a common interface that is implemented by all the classes.

  • Have all the classes inherit from a base classes that provides the query functionality.

  • Add the query functionality to a base class with the public access modifier.

Explicación

Pregunta 17 de 20

1

INCOMPLETE

You are writn code for a new method named Process:

void Process (object o)
{
//code goes here...
}

The code received a parameter of type object. You need to cast this object into the type Rectangle. At times, the value of o that is passed to the method might not be a valid Rectangle value. You need to make sure that the code does not generate any System.InvalidCastExpection errors while doing the conversion. Which of the following lines of code should you use inside the Process method to accomplish this goal?

Selecciona una de las siguientes respuestas posibles:

  • INCORRECT

    Rectangle r = o is Rectangle;

  • Rectangle r = (o != null) ? o as Rectangle: (Rectangle) o;

  • Rectangle r = o as Rectangle;

  • Rectangle r = Rectangle) o;

Explicación

Pregunta 18 de 20

1

INCOMPLETE

Classes that want to support comparison must implement the IComparable interface and then provide a body for the _______ method.

Selecciona una de las siguientes respuestas posibles:

  • INCORRECT

    ==

  • CompareTo

  • Main

  • isA

Explicación

Pregunta 19 de 20

1

INCOMPLETE

In a class, you defined a method called Render. This method provides functionality to render bitmap files on a the screen. You would like the derived classes to supersede this functionality to support the rendering of additional image formats. You also want the Render method of the derived classes to be executed even if a derived class is cast as the base class. Which keyword should you use with the definition of the Render method in the base class?

Selecciona una de las siguientes respuestas posibles:

  • INCORRECT

    abstract

  • INCORRECT

    overrides

  • new

  • virtual

Explicación

Pregunta 20 de 20

1

INCOMPLETE

Which of the following are value types (not reference types)? choose all that apply.

Selecciona una o más de las siguientes respuestas posibles:

  • float

  • struct

  • INCORRECT

    string

  • INCORRECT

    class

  • int

  • method

  • INCORRECT

    delegate

Explicación