In: Computer Science
1.For Python Which statement(s) are true regarding private class variables?
private variables can be accessible inside the class.
private variables can be accessible outside the class.
private variable values can be changed directly outside of the class
private variables can be changed outside the class through set methods.
2.
In the following code,
def A:
def __init__(self):
__a = 1
self.__b = 1
self.c = 1
__d__ = 1
# Other methods omitted
Which of the following is a private data field?
Group of answer choices
__a
__b
c
__d__
3.
Analyze the following code and choose the more accurate
statement.
class A:
def __init__(self, s):
self.s =
s
def print(self):
print(s)
a = A("Welcome")
a.print()
Group of answer choices
The program has an error because class A does not have a constructor.
The program has an error because class A should have a print method with signature print(self, s).
The program has an error because class A should have a print method with signature print(s).
The program would run if you change print(s) to print(self.s).
4.
Which of the following statement is most accurate?
Group of answer choices
A reference variable is an object.
An object is a reference type variable
An object may contain other objects.
An object may contain the references of other objects.
5.
Which special method returns a string representation of the object?
Group of answer choices
__init__ method
print method
__str__ method
constructor
6.
Class design should include ________
Group of answer choices
fields
constructor
accessor and mutator methods
other useful methods
All of the above
7.
What is max("Programming is fun")?
Group of answer choices
P
r
blank space character
u
8.
What is "Programming is fun"[1:3]?
Group of answer choices
Pr
Pro
ro
rog
1.For Python Which statement(s) are true regarding private class variables?
Answer: private variables can be accessible inside the class.
private variables can be changed outside the class through set
methods.
2. def __init__(self):
__a = 1
self.__b = 1
self.c = 1
__d__ = 1
# Other methods omitted
Which of the following is a private data field?
Answer: self.__b
self.__b is a private field
3. Analyze the following code and choose the more accurate
statement.
class A:
def __init__(self, s):
self.s = s
def print(self):
print(s)
a = A("Welcome")
a.print()
Answer: The program would run if you change print(s) to print(self.s)
4. Which of the following statement is most accurate?
Group of answer choices
A reference variable is an object.
An object is a reference type variable
An object may contain other objects.
An object may contain the references of other objects.
Answer: An object may contain the references of other objects.
5. Which special method returns a string representation of the object?
Answer: __str__
6.Class design should include ________
Group of answer choices
fields
constructor
accessor and mutator methods
other useful methods
All of the above
answer: All of the above
7. What is max("Programming is fun")?
Group of answer choices
P
r
blank space character
u
answer: u
8. What is "Programming is fun"[1:3]?
Group of answer choices
Pr
Pro
ro
rog
Answer: ro