All are multiple choice questions, please answer all if possible, Will give big
ID: 3898768 • Letter: A
Question
All are multiple choice questions, please answer all if possible, Will give big thumbs up,It is greatly appreciated! Thank you 2. Consider the following code snippet: public class Vehicle private String type; public String Vehicle(String type What is wrong with this code? a) The class instance variable type must be initialized when it is declared b) The constructor must not have any arguments. c) The constructor must not have a retun type declared. d) The constructor's return type must be void. 3. The process of hiding object data and providing methods for data access is called a) documentation b) extension c) encapsulation 4. Which of the following statements about classes is correct? a) A class is an object that can be manipulated by a program. b) A class describes a set of objects with the same behavior c) Class is another name for a method. d) A class can contain only methods. S. Consider the following code snippet: Coin coin1 new Coin("dime, 0.10); Coin coin2 = new Coin("dime", 0.10); Which of the following statements is correct? a) coin1 and coin2 contain references to the same object. b ) coin 1 and coin2 refer to the same object. c) coin1 and coin2 contain the same memory location d) coin1 and coin2 each have their own set of instance variables. 6, Trying to access an element that is outside of the valid indices of an array generates what type of exception? a) NumberFormatException c) ArrayIndexoutofBoundsException b) IShouldHaveStudiedChapterTException d) IllegalStateException Consider the statement: Apple[] cart- new Apple[512 What type is cart [131 a) integer b) Apple c) String d) unknown All of the following are methods of the ArrayList class except: c) set0 8. a) length0 b) size0 d) get0
Explanation / Answer
2.
c) The constructor must not have a return type declared .
public Vehicle(String type) is the correct declaration.
3.
c) encapsulation
All data are declared private inside the class , so cannot be accessible outside the class. The methods using the data are declared public and can be accessed outside the class.
4.
b) A class describes a set of objects with the same behavior.
5.
d) coin1 and coin2 each have their own set of instance variables.
?coin1 and coin2 are seperate instance variables created with different memory locations using new.
6.
c) ArrayIndexOutOfBoundsException
7.
b) Apple
cart is an array of 512 objects of class Apple
8.
a) length()
length is function used with array while size(),set() and get() methods are used with arraylist.
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.