This quiz works best with JavaScript enabled. Home > Class 11 > Class 11 Computer Science Chapter 6 File Handling – Quiz 2 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 2 (25 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Which mode is correct for writing binary file? A) "w". B) "wb". C) "bw". D) "w+". Show Answer Correct Answer: B) "wb". 2. Which mode is used to open a binary file for writing? A) R. B) W. C) Wb. D) Rb. Show Answer Correct Answer: C) Wb. 3. Fread() reads contents of file A) Word by word till eof. B) Paragraph by paragraph till end of file. C) Line by line till eof. D) None. Show Answer Correct Answer: C) Line by line till eof. 4. How do you read a file line by line in Python? A) Use 'open("filename.txt") and file.read()' to get the content as a single string. B) Use 'file.readlines()' to read all lines in a file. C) Use 'open("filename.txt") as file:file.read()' to read the entire file at once. D) Use 'with open("filename.txt") as file:for line in file:print(line)'. Show Answer Correct Answer: D) Use 'with open("filename.txt") as file:for line in file:print(line)'. 5. How do you handle exceptions while working with Fileinputstream and Fileoutputstream in Java? A) Use try-catch blocks to catch and handle IOException. B) Use if-else statements to handle IOException. C) Throw a new custom exception instead of catching IOException. D) Ignore the exception and continue with the program. Show Answer Correct Answer: A) Use try-catch blocks to catch and handle IOException. 6. Describe how to serialize an object in Python. A) Convert the object to a string using 'str(object)' before saving. B) Use 'xml.etree.ElementTree' to serialize the object to XML. C) Use 'json.dumps(object)' for JSON serialization. D) Use 'pickle.dump(object, file)' for binary serialization. Show Answer Correct Answer: C) Use 'json.dumps(object)' for JSON serialization. 7. Ali opens a file with mode "r" . He tries to write new data into it, but an error occurs. Why? A) The file is locked for editing. B) The file is opened as read-only, not writable. C) The file does not exist. D) The file is already closed. Show Answer Correct Answer: B) The file is opened as read-only, not writable. 8. Dalam C++, fungsi mana yang digunakan untuk membuka file? A) Open(). B) Create(). C) Start(). D) Init(). Show Answer Correct Answer: A) Open(). 9. Using append overwrites all data in a text file A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 10. Which function is used to read a single line from a file A) Readline(). B) Readlines(). C) Readstatement(). D) Readfullline. Show Answer Correct Answer: A) Readline(). 11. What is the code to open a file named as new ..... file in write mode and truncate it if it already exists? A) Open("new file.dat", | );. B) Open( | , "new file.dat" );. C) Open(ios::out | ios::trunc, "new file.dat" );. D) Open("new file.dat", ios::out | ios::trunc );. Show Answer Correct Answer: D) Open("new file.dat", ios::out | ios::trunc );. 12. What are the different modes of opening a file in C++? A) Ios::create. B) Ios::in, ios::out, ios::app, ios::ate, ios::trunc, ios::binary. C) Ios::read. D) Ios::write. Show Answer Correct Answer: B) Ios::in, ios::out, ios::app, ios::ate, ios::trunc, ios::binary. 13. What does the tell() function return in Python file handling? A) File creation date. B) Current position of the file pointer. C) Number of lines in the file. D) Total file size. Show Answer Correct Answer: B) Current position of the file pointer. 14. In Python, which function do you use to open a file? A) Start(). B) Open(). C) Load(). D) Read(). Show Answer Correct Answer: B) Open(). 15. What is the purpose of closing a file after it is no longer being used? A) To prevent data corruption. B) To write data automatically. C) To delete the file. D) To change file permissions. Show Answer Correct Answer: A) To prevent data corruption. 16. Which exception is thrown when divide by zero occurs? A) NumberFormatException. B) ArithmeticException. C) NullPointerException. D) None of these. Show Answer Correct Answer: B) ArithmeticException. 17. How do you close a file after performing file operations in C++? A) 'file.open()'. B) 'file.end()'. C) 'file.close()'. D) 'file.read()'. Show Answer Correct Answer: C) 'file.close()'. 18. What will be the output of the following code snippet?f = Nonefor i in range (5):with open("myfile.txt", "w") as f:if i > 2:breakprint (f.closed) A) Runtime Error. B) True. C) False. D) Hello world. Show Answer Correct Answer: B) True. 19. What is the result of trying to access an index that is out of range in a list? A) IndexError. B) ValueError. C) TypeError. D) NameError. Show Answer Correct Answer: A) IndexError. 20. Vi stands for A) Visual editor. B) Voice editor. C) Victory editor. D) Vector editor. Show Answer Correct Answer: A) Visual editor. 21. Which of the following class is used for input and output operation when working with characters? A) InputStream. B) OutputStream. C) Writer. D) All of given. Show Answer Correct Answer: C) Writer. 22. How is Java serialization achieved? A) By using the java.io.Serialization class. B) By calling the serialize() method. C) By implementing the java.io.Serializable interface. D) By setting the serialization flag to true. Show Answer Correct Answer: C) By implementing the java.io.Serializable interface. 23. What is the purpose of the 'close' method in file handling? A) To create a new file and write data to it. B) To close an open file and release resources. C) To delete a file from the system permanently. D) To read data from a file and store it. Show Answer Correct Answer: B) To close an open file and release resources. 24. Which is/are the basic I/O (input-output) stream(s) in file? A) Standard Input. B) Standard Output. C) Standard Errors. D) All of these. Show Answer Correct Answer: D) All of these. 25. Why is Binary File Handling important in Python programming? A) Binary File Handling is crucial for handling non-text files and preserving data integrity. B) Binary File Handling can corrupt data easily. C) Binary File Handling is only useful for text files. D) Binary File Handling is not supported in Python. Show Answer Correct Answer: A) Binary File Handling is crucial for handling non-text files and preserving data integrity. ← PreviousNext →Related QuizzesClass 11 Computer Science Chapter 6 File Handling Quiz 1Class 11 Computer Science Chapter 6 File Handling Quiz 3Class 11 Computer Science Chapter 6 File Handling Quiz 4Class 11 Computer Science Chapter 6 File Handling Quiz 5Class 11 Computer Science Chapter 6 File Handling Quiz 6Class 11 Computer Science Chapter 6 File Handling Quiz 7Class 11 Computer Science Chapter 6 File Handling Quiz 8Class 11 Computer Science Chapter 6 File Handling Quiz 9Class 11 Computer Science Chapter 6 File Handling Quiz 10Class 11 Computer Science Chapter 6 File Handling Quiz 11 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books