In: Computer Science
1) Which answer is the best description of “parsing”. (3pts)
A. Converting a double to an int with the (int) cast operator
B. Reading a file of textual records and writing them to a new file
C. Taking apart and converting text data to other forms
D. Performing a database query
2) What is an advantage of encapsulation? (3 pts)
A.Shields the data of the class
B.Can control access via an API
C.Easier to test
D. Improves maintainability and reusability
E. All of the above
3) What is the difference between a class and an instance of a class? (3pts)
A. A class lists the methods and the instance lists the state variables.
B. A class is a template for state variables and methods in an object. An instance of a class is a specific object of the class created by the new command.
C.A class has to have at least one instance.
D.A class does not have a .java file but an instance does.
E. Every instance of a class has a different API.
4) What is an example of “tokenizing”? (3pts)
A.Creating an array and assigning values with a Scanner loop
B. Splitting a String into an array of Strings using a delimiter (e.g., “\t”)
C. Iterating through the characters of String variable
D.Using String.substring to isolate a particular part of a string
E.Converting a string to uppercase.
5) Which of these statements declares an ArrayListthat contains only Student objects(objects that are instances of Student)?(Assume no subclassing) (3pts)
A. ArrayList myStudentList = new ArrayList();
B. ArrayList
C. ArrayList
D. ArrayList
E. ArrayList
1) The correct answer should B)
Explanation:
A) is wrong as converting from one datatype to another is known as typecasting.
C) and D) are wrong as querying a database or converting text from one form to another is also not parsing.
B) is correct as reading or writing files can be said as parsing.
2) The correct answer is E
Explanation:
Encapsulation has many advantages like the reusaility of code as mentioned above.
Also, the shielding of the private variable from the outside world and others like Maintanibiity and testing.
So all of the above are correct
3) The correct answer is B)
Explanation:
A class is just a template defined by us which says that, whatever object would be created using that class will follow the template we created.
The objects are created using the new keyword
We can create as many obects we want using the new keyword
4) The correct answer is B)
Explanation:
Tokenizing refers to splitting anything into multiple parts.
So, when we break a String into multiple Strings based on \t, this can be said as tokenizing.
5) The correct answer is C)
Explanation:
In the option C declaration, Student class is mentioned already there.
That means, if no subclassing is there, only the objects of the Student class can be put inside that Array List.
SO, this is the correct option.