Object Oriented Principals

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Abstraction is one of the pillars of Object-Oriented Programming. Which of the following conversations describes the abstraction? (Choose all that apply) A - B: Sarah, I want to give drivers a warning when their fuel is low. We don't currently have a way to check for that. B - B: Sarah, we've been assigned to add a sensor to automatically defrost windows for safety purposes. What do you think? C - B: Sarah, we've been assigned to work on the self-driving feature for the new model. How do you suppose we handle the dilemma of prioritizing the passengers, or prioritizing pedestrians?

Answer: A & B

What is the purpose of Objects in Object-Oriented Programming? (Choose one) A - To bundle data and behavior in one container B - To create variables by value, instead of by reference C - To resolve run-time type ambiguity D - To adhere to industry standard naming conventions

Answer: A - To bundle data and behavior in one container

Encapsulation is considered one of the pillars of Object-Oriented Programming. One aspect of encapsulation deals with information Hiding. This can be done through setting access levels for variables and functions. Match the protection levels with the correct definition. (Matching) A - Access is not restricted in any way. B - Access is restricted to its own class or any children derived from this object. C - Access is restricted to its own class only.

Answers: A - Public, B - Protected, C - Private

Polymorphism is considered one of the pillars of Object-Oriented Programming. Which of the following examples clearly explain how it can be used? (Choose all that apply) A - A base class called "Animal" has a virtual "Speak" function. A child class "Cat" overrides the "Speak" function and prints "Meow" to the screen. B - A class called "Calculate" has the following two functions: public void AddNumbers(int firstNumber, int secondNumber) { //implementation } public void AddNumbers (int firstNumber, int secondNumber, int thirdNumber) { // implementation } This is called function overloading. Function overloading is a form of polymorphism. C - A class called "inventoryItem" is created with the virtual function "Use". The inventory system contains an array of inventoryItems. Child classes, such as "HealthPotion" override the "Use" function to heal the player. The inventorySystem doesn't know what kind of item is stored in the slot. When the user wants to use the item, it does not cast the InventoryItem. It simply calls the "Use" function. The program determines at run-time that the inventory item is in fact a health potion and uses that version of the function, instead of the base class version. This is a process called "Late Binding" which is a form of run-time polymorphism. D - None of these are examples of polymorphism.

Answer: A, B, & C

Inheritance is considered one of the pillars of Object-Oriented Programming. Which of the following examples illustrates the concept of inheritance? (Choose one) A - The Ford Model T is considered by many to be the father of modern automotive vehicles. B - There are three types of mammals. C - In games like Final Fantasy.

Answer: B - There are three types of mammals.

Which of the following operators can be used to access the member function of a class? (Choose one) A - : a single colon B - :: a doible colon C - . a single period D - # a single octothorp

Answer: C - . a single period

Consider the following code: class MyClass { public MyClass() { Console.Writeline("Parameterless Constructor Called"); } public MyClass (int temp) { int someInt = temp; someInt += 2; Consone.WriteLine("Constructor With Parameter Called"); } } class Program { static void Main(string[] args) { MyClass a = new MyClass(5); MyClass b = new MyClass(); Console.Readline(); } } In the Main() function, two objects of type MyClass are created. Based on the code, what do you expect the output to look like? (Choose one) A - Parameterless Constructor Called Parameterless Constructor Called B - Constructor With Parameter Called Constructor With Parameter Called C - Parameterless Constructor Called Constructor With Parameter Called D - Constructor With Parameter Called Parameterless Constructor Called

Answer: D - Constructor With Parameter Called Parameterless Constructor Called

Consider the following code: class Example { private int someNumber; public int anotherNumber; private voide DisplayOne() { Consle.WriteLine(someNumber + " " + anotherNumber); } public voide DisplayTwo() { Console.WriteLine(someNumber + " " + anotherNumber); } } What errors do you observe with the code? (Choose one) A- anotherNumber cannot be declared as public in this scope. B- DisplayOne cannot be declared private since it makes use of a public member variable. C - DisplayTwo is public, so it cannot access the private member variable someNumber as that would violate encapsulation. D - There are no errors with this class.

Answer: D - There are no errors with this class


Set pelajaran terkait

Business Analytics 2600 Final Exam Review

View Set

Managerial Accounting 1 - Besser - Study Guide Test 4

View Set

PHYS 108: Physical Science II Test 4

View Set

Medical Terminology Ch 17: The Female Reproductive System

View Set

3.2 Measures of Dispersion Homework

View Set

BURNS TEST 3/Lippencott/priority & new priority

View Set