1-To create an ArrayList of strings, which of the following is correct?
`a |
ArrayList<String> list = new ArrayList<String>(); |
b |
ArrayList<String> list = new String<String>[]; |
c |
ArrayList<String> list = new ArrayList<String>; |
d |
ArrayList[String] list = new ArrayList[String]; |
2-All instance variables?
a |
Are assigned a default value if they are not initialized |
b |
Must be initialized as part of their declaration |
c |
Are assigned an arbitrary value if they are not initialized |
d |
Must be initialized by the constructor |
3-An instance method may only be invoked on
a |
An instance variable |
b |
A constructor |
c |
A class |
d |
An object |
4-Each object contains its own copy of
a |
Constructors |
b |
Constructors, methods, and variables |
c |
Instance variables |
d |
Instance methods |
Please provide a correct answer..
Note that the questions are about java.
Ans1) Correct Option :- A ArrayList<String> list = new ArrayList<String>();
Explanation :- As it is the correct syntax to create the array list.
Ans2) Correct Option : A Are assigned a default value if they are not initialized
Explanation :- Since, instance variable have default value. For numbers, the default value is 0, for booleans it is False, and for object references it is null.
Ans3) Correct Option : D An object
Explanation :- To call a instance method, we have to create an Object of the class within which it defined.
Ans4) Correct Option : B Constructors, methods, and variables
Explanation :- Since, each object is blue print of the class.
Get Answers For Free
Most questions answered within 1 hours.