Question: Need help answering a few questions about object-oriented programming with Python 3! 1. What happens if we create an attribute whose name starts with __?

Need help answering a few questions about object-oriented programming with Python 3!

1. What happens if we create an attribute whose name starts with "__"?

A. Error

B. Nothing special

C. Python automatically appends _, where is the name of the class, in front of the attribute name when accessed from outside the class

D. It makes it impossible to access this attribute from outside the class

2. Creating a public interface is important because

A. It provides a set of methods for a user to use in order to ensure that attributes are set and gotten correctly.

B. It keeps attribute data private within the class

C. It allows for abstraction

D. It provides a set of alternative constructors for creating an instance of a class

3. All classes must define an __init__ method

A. True

B. False

4. Attributes of a class can only be basic data types (integer, floating point numbers, etc..)

A. True

B. False

5. The myMethod method of a class is defined below:

def myMethod(self, y) x = y

What is happening in the line x=y?

A. A syntax error occurs

B. The attribute x is assigned the value stored in y

C. An attribute of the object is created (and called x) and assigned the value stored in y

D. A local variable x is created and assigned the value stored in y

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!