Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Unit 3 - Classes

1)A class is……


A. An object factory
B. A blueprint to create objects
C. A specification for objects
D. All of these
Ans: D
Explanation
A class is a template or blueprint for multiple objects
with similar features and maybe regarded as a
specification for creating similar objects. So all of the
options are applicable for class.

2)………… represents an entity in the real-world with its


identity and behavior.
A. A class
B. An object
C. A procedure
D. A method
Ans: B
Explanation
An object is an identifiable entity with a set of
attributes, behavior and state.

3)……….. is a template to create similar objects that share


common characteristics and behavior
A. A method
B. A procedure
C. An attribute
D. A class
Ans : D
Explanation
A class is a template or blueprint for multiple objects
with similar features and maybe regarded as a
specification for creating similar objects.

4. What is setattr() used for?


A) To access the attribute of the object
B) To set an attribute
C) To check if an attribute exists or not
D) To delete an attribute
Ans:B
Explanation
setattr(obj,name,value) is used to set an attribute. If
attribute doesn’t exist, then it would be created.

5). Is the following Python code correct?

A) True
B) False
Ans : A
Explanation
It is possible to delete an object of the class. On further
typing obj in the python shell, it throws an error
because the defined object has now been deleted.

Unit 4 – Files
1)The readlines() method returns ____________
A) Str
B) a list of lines
C) a list of single characters
D) a list of integers
Ans: A
Explanation
Every line is stored in a list and returned.

2)To read the remaining lines of the file from a file object
infile, we use ____________
A) infile.read(2)
B) infile.read()
C) infile.readline()
D) infile.readlines()
Ans: D
Explanation
Execute in the shell to verify.

3) To open a file c:\scores.txt for reading, we use


_____________
A) infile = open(“c:\scores.txt”, “r”)
B) infile = open(“c:\\scores.txt”, “r”)
C) infile = open(file = “c:\scores.txt”, “r”)
D) infile = open(file = “c:\\scores.txt”, “r”)
Ans :B
Explanation
Execute help(open) to get more details.

4)Which of the following statements are true?


A) When you open a file for reading, if the file does not
exist, an error occurs
B) When you open a file for writing, if the file does not
exist, a new file is created
C) When you open a file for writing, if the file exists, the
existing file is overwritten with the new file
D) All of the mentioned
Ans: D
Explanation
The program will throw an error.

5)What will be the output of the following Python code?

A) True
B) False
C) None
D) Error
Ans: A
Explanation
The WITH statement when used with open file
guarantees that the file object is closed when the with
block exits

Unit 5 - XML and Serialization


1.What is serialization?
A) Turning object in memory into stream of bytes
B) Turning stream of bytes into an object in memory
C) Turning object in memory into stream of bits
D) Turning stream of bits into an object in memory
Ans: A
Explanation
Serialization in Java is the process of turning object in
memory into stream of bytes.

2.Serialized object can be transferred via network


A) True
B) False
Ans: A
Explanation
Serialized object can be transferred via network
because Java serialized object remains in form of bytes
which can be transmitted over network.

3)XML stands for


A) Extensible Mashup Language
B) Extended Mashup Language
C) Extensible Markup Language
D) None of these
Ans:B
Explanation
A markup language is a set of codes, or tags, that
describes the text in a digital document. The most
famous markup language is hypertext markup language
(HTML), which is used to format Web pages
4. What type of members are not serialized?
Aa ) Private
B) Protected
C) Static
D) Throwable
Ans:C
Explanation
All static and transient variables are not serialized.

5.Which of the following is not a XML storage option?


A) Native Storage as XML data Type
B) Mapping between XML and relational Storage
C) Small Object Storage
D) None of the Mentioned
Ans: C
Explanation
XML uses large object storage which uses varchar(max)
and varbinary(max).

You might also like