IT 209 Midterm Practice Quiz- GMU

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

Which of the following statement is true?

Class bundles together similar object OOP models real life problems OOP is a way to create custom data type in Python

Method overriding is altering or replacing a method of the superclass with a new method with a different name in the subclass.

False

Write exact outcome of the following code? class Point(object): def __init__(self, x, y): self.x = x self.y = y def equal(self, other): if self.x == other.x and self.y == other.y: return True else: return False p1 = Point(4,21) p2 = Point(4, 30) print(p1.equal(p2)) #outcome of this line

False

super() function call can only be made in the __init__ method

False

What does pop() function do?

It removes an element with the specified key and returns the value.

What does the dictionary method values() return?

only values

What is the right way to access a class variable "Doors" for a class named 'Car'?

Car.Doors

What will be the outcome of the following code? class Cat(object): def sound(self): print ("Meoww") class Dog(object): def sound(self): print ("Woof woof!") def makeSound(animalType): animalType.sound() c = Cat() #Cat object d = Dog(). #Dog object makeSound(c) makeSound(d)

'Meoww' then 'Woof woof!'

What will the following code print? def sq(x, y=0): return x*y calc = sq(5) print(calc)

0

Write exact outcome of the following code as generated by last print statement. class Student (object): total = 0 def __init__(self, name, address): self.name = name self.address = address Employee.total += 1 e1 = Student ('Jane Doe', '4400 Univ Dr.') e2 = Student ('Mary Mont', '7800 Fairy Tree') e3 = Student ('Mike Yung', '400 Mass Ave') print(Student.total) #outcome of this line

0 or 3??

What is a third of 120?

40

Any variable defined inside a function is considered to be in ______ scope?

Local

Which of the following is True about abstract base class (ABC)?

No need to implement all necessary methods (and properties) in base class

What would be the output of: range(9, 14, -1)?

No outcome

By default, _____ class is the parent of all classes we define in Python. (Write the exact answer w/o any space)

Object

Which one is correct about Overriding concept?

Overriding is altering or replacing a method of the superclass/parent class with a new method with the same name in the subclass

Below is a definition of a polymorphic function and a class. What will be the outcome of the following code? class Animal(object): def audio_sound(self): print('Boo Boo!') def makeSound(animalType): animalType.sound() #function call a = Animal() makeSound(a) #outcome of this line

Raise an error

'self' refers to current object.

True

Is this true or false: All exceptions must extend the BaseException class or one of its subclasses.

True

True or false: "__" is being used before a method / argument name to indicate that the method / argument is private.

True

What would be the value of the following expression: True and False or True?

True

__init__ method is called constructor and it is for when we create an instance of a class (an object)

True

What would be the content of list2 at the end? list1 = [5, 20] list2 = [1, 3] list2.extend(list1)

[1,3,5, 20]

What would be the content of s2 after slicing operation? s1 = "OBCD_EF_G" s2 = s1[4:8]

_EF_

You are given the following __init__ method for class 'Animal'. Which of the following will create a Animal object with name, "Bear" and "2" legs. def __init__(self, name, number): self.name = name self.number = number

a = Animal ("Bear", 2)

Which of the following is a valid definition of 'Animal' class?

class Animal (object)

What is the correct definition of a class ComboMachine, that has two parents RiceCooker and SlowCooker?

class ComboMachine(RiceCooker,SlowCooker):

Define a class Monkey which is a subclass of Mammal. Just provide the definition line.

class Monkey(Mammal):

What is the correct way to add an item ('VA', 'Virginia') to a dictionary d where key = 'VA' and value = 'Virginia'?

d['VA'] = 'Virginia'

Which of the following syntax is right way to access instance variable date_of_birth of a Person class object "h"?

h.date_of_birth


Set pelajaran terkait

ISY 143 Chapter 9 Network Fundamentals

View Set

Professional Exam Situational Practice

View Set

Pharm Chapter 57: Ophthalmic Drugs

View Set

INTL Business Midterm - CH 3 & 4 & 5 REVIEW

View Set

chapter 4 - digital communication // edexcel igcse ict (9-1)

View Set

Final Exam Operations Management

View Set

Active Directory Chapter 2 (DNS)

View Set

Specimen Collection: Lesson 4 Post-Test

View Set