No student devices needed. Know more
20 questions
Which of the following statements is true about Object-Oriented Programming?
You can define your own objects with unique data and behavior.
You can only use the objects that are defined for you by the programming language.
It is best to make all data public for easy access by other objects.
Objects can only be used by one program and never shared with other programs.
If you use an object without understanding or accessing internal details, what OOP concept are you using?
Encapsulation
Inheritance
Polymorphism
Data-sharing
. Given the code below, where should you define a new function that belongs to the Player class? // LINE A using UnityEngine; using System.Collections; public class Player { // LINE B public Player() { // LINE C } } // LINE D
LINE A
LINE B
LINE C
LINE D
Which of the following class variables can be freely read and modified by code outside the object?
public int score1;
private float cost;
protected string message;
visible bool gameOver;
Which of the following variable declarations uses a reference data type?
Flower myFlower;
float mySize;
int myScore;
void deepSpace;
Given the following line of code, what does the variable myRobot contain, by default? Robot myRobot;
0
Null
A reference to a newly created Robot object
An empty string
Given the following code, which of the Robot objects will have the longest lifespan? public class MyScript : MonoBehaviour { private Robot classRobot = new Robot(); public void Start() { Robot localRobot = new Robot(); } }
classRobot
localRobot
They will both live the same amount of time
It depends on how the object is added to the Unity scene
How many Robot objects are created by the following code? Robot myRobot1 = new Robot(); Robot myRobot2 = myRobot1; Robot myRobot3 = new Robot(); Robot myRobot4 = myRobot3;
1
2
3
4
Which of the following things are required in all function definitions?
The name of the function
Opening and closing parentheses where optional data parameters are placed
Opening and closing curly braces to mark the body of the function
All of these are required
What keyword do you use in front of a function name to show the function returns no data?
Void
Null
Empty
All functions must return some data
Given the following function declaration, which line of code returns the correct data? string getMessage()
return "Game Over";
return 0;
return true;
return new Robot();
How would you call the StopGame() function if it requires an int and a bool parameter, in that order?
StopGame(42,true);
StopGame(true;42);
StopGame(42);StopGame(true);
StopGame("42","true");
When a class in a C# script inherits from the MonoBehaviour base class, how can it find the value of the tag that is currently applied to the GameObject associated with the script?
By reading the tag variable inherited from MonoBehaviour
By calling GetTag()
By calling GetValue("tag")
By calling GetComponent()
When a class in a C# script inherits from the MonoBehaviour base class, how can it get a reference to a RigidBody2D component that might be attached to the GameObject associated with the script?
Rigidbody2D rb = GetComponent ();
Rigidbody2D rb = GetComponent(Rigidbody2D);
Rigidbody2D rb = rigidBody;
Rigidbody2D rb = FindComponent("Rigidbody2D");
Which of the following components is always present on a GameObject, and therefore has a dedicated MonoBehaviour variable with a reference to it?
Transform
Collider2D
Rigidbody2D
PhysicsMaterial2D
What is risky about the following code? GameObject predator = GameObject.Find("Shark"); Debug.Log("Look out for " + predator.name);
f there is no GameObject with the name "Shark", predator will be null and cause a run-time exception when you try to read the name from the reference.
It will only work in the Update() function, but not in the Start() function.
It will only work if the current object has a tag with a matching "Shark" value.
If there is more than one GameObject named "Shark", the results are unpredictable.
Given the following class, what is the name of the constructor function? class Mirror { public Mirror() { } public void BuildObject() { } public void Construct() { } }
Mirror
BuildObject
Construct
Any of these can be used as the constructor
What happens to class variables when you don't initialize them in a constructor function?
C# will assign default values to them.
Those variables are automatically deleted from the object.
You will get a compile-time error; the program will not build correctly.
The variables will be assigned random data.
According to Microsoft's C# documentation, which of the following statements best describes a "property"?
Special public syntax that lets you write small getter and setter functions to manage access to private data
A private class variable that can only be accessed by code within the class
A descriptive value like "blue" or "fast"
A place where objects are kept when they are not being used in a scene
Given the following Calculator class, which of the following statements is true? class Calculator { private int result; public int Result { set { if (value >= 0) { result = value; } } } }
Code outside the calculator class can update the private result but cannot read the current data in the result variable.
Code outside the calculator class cannot set the private result value to less than zero.
This code demonstrates a "property".
All of these are true.
Explore all questions with a free account