Quiz: Apply object-oriented principles

Quiz

Beginner

+60 XP

15m

Unity Technologies

Quiz: Apply object-oriented principles thumbnail

This quiz will assess your understanding of the concepts covered in the Junior Programmer: Apply object-oriented principles mission.

Question 1

True or False:

In general, classes should be organized and written such that each class has a singular purpose.

Select only one

Question 2

Why might you want to use an extension method in C#?

Select only one

Question 3

Which of the following statements are true about parent (base) and child (derived) classes?

  1. A class can only inherit from a single class.
  2. Protected variables and methods can be accessed from the child class, even if they are separate scripts.
  3. Private variables and methods can be accessed from the child class, even if they are separate scripts.
  4. If Class C derives from Class B, which derives from Class A, Class C only inherits behaviors from Class B.

Select only one

Question 4

If you were programming an application that allowed users to configure their own vehicles, how would you use the concept of inheritance to structure the code in a way that minimized redundancies?

Select only one

Question 5

A base class (Class A) includes the following code:

public virtual void Greet () 
{
   Debug.Log("Hello");
}

A derived class (Class B) that derives from Class A includes the following code:

public override void Greet ()
{
   Debug.Log("How are you?");
}

If only Class B is instantiated and the Greet() method is called, what will appear in the console?

Select only one

Question 6

Which of the following practices are in support of the principle of “encapsulation” in C#?

  1. Using getters and setters
  2. Using public variables only when necessary
  3. Deactivating objects in a scene that are not in use whenever possible.
  4. Using events that communicate only to abstract classes.

Select only one

Question 7

How would you replace the public variable below with a Property, which has improved security and still can be accessed from other classes.

public int score;

Select only one

Question 8

How would you recommend improving the following code in order to improve its reusability?

void DisplayInfo(string name1, string name2, string address1, string address2, string phone1, string phone2)
{
     print(name1);
     print(name2);
     
     print(address1);
     print(address2);
     
     print(phone1);
     print(phone1);

}

Select only one

Question 9

The following is an example of code logic that is very difficult to understand:

public float GetValue()
{
     float result;      
     
     if (bool1)
     {
          result = 1;
      }
      else
      {
         if (bool2)
         {
            result = 2;
         }
         else
         {
            result = 0;
         }
     }
     return result;
 }

True or False: the code below would achieve the same result in a simpler way.

public float GetValue() {
     if (bool1)
     {
         return 1;
     }
     if (bool2)
     {
         return 2;
     }
     return 0; 
}

Select only one

Question 10

Which of the following statements about variables is true?

Select only one

Question 11

When using the profiler to diagnose issues with CPU usage, where would you look to find optimization issues with custom scripts you have written for your application?

Select only one

Question 12

Which of the following scenarios is most likely to cause performance issues?

Select only one

Submit answers

To calculate your score, submit your answers to the quiz. A passing score will mark this quiz complete.

Correct answers needed to pass

9/12

Retake allowed after

0 Mins