std 12-CHAPTER-9
std 12-CHAPTER-9
and String
Textbook Solution
1. Which of the following refer to the starting index value in arrays?
a. 0
b. 1
c. Null
d. All of these
2. What is the size of second dimension in an array sales [5] [12]?
a. 5
b. 12
c. 60
d. 10
3. What will expression sales.length return for an array sales [5] [12]?
a. 5
b. 12
c. 60
d. 120
4. When an array sales [5] [12] is declared without specifying initial values,
what is the initial value of sale [0] [0] ?
a. 0
b. default value
c. compilation error
d. 60
5. What does ‘length’ refer to for an object of String class?
a. attribute
b. method
c. class variable
d. class name
6. If ‘str’ is the object of String class and its content is “Thank GOD”, then
what is the value of str.length()?
a. 9
b. 10
c. 8
d. 11
7. What type of value is returned when we use get method of Calendar
class with constant DAY_OF_WEEK as an argument?
a. int
b. char
c. string
d. boolean
Exam Oriented MCQs
1. What do we call the basic data type which can store only one value at a time?
a) Scalar variable b) Local variable c) Static variable d) Instance variable
2. What do we call the data type that can be used to store a collection of more
than one data values?
a) Scalar b) Composite c) Constructor d) Basic
3. Which of the following is a variable representing a collection of homogeneous
type of elements?
a) Array b) Method c) Class d) Object
4. is useful to represent vector, matrix, and other multi -dimensional
data.
a) Array b) Method c) Class d) Object
5. is a 1D data structure that can be used to store list of items in Java.
a) Vector b) Matrix c) Composite d) Static
6. is used to represent 2 – D data structure.
a) Vector b) Matrix c) Composite d) Static
7. Which of the following is useful when same operation is to be performed on
various elements of similar type?
a) Array b) Constructor c) Method d) Object
8. How do we identify each element of array?
a) By an index position b) By a pointer
c) By memory allocation d) All of above
9. An index position of an array is associated with array ………………..
a) class b) variable c) Method d) function
10. Creating an array is how many steps process?
a) Declare an array object b) Create an array object
c) declare an array class d) Both a and b
11. An array object can be created in how many ways?
a) Using new operator and specifying the size
b) Directly initializing the content of array
c) Specify the size d) Both a and b
12. To declare 1–D array we use a pair of …………… brackets after array name or after
data type.
a) [ ] b) { } c) ( ) d) < >
13. Write down the syntax to declare array.
Ans. <data type ><array name> [ ]; OR <data type> [ ] <Array name>;
14. Write down the various ways to create Array object named “marks” with size for
5 elements
a) int marks[ ]; marks = new int [5]; b) int marks [ ] = new int [5];
c) int [] marks = new int [5]; d) All of above
15. How many bytes are used to store the int marks[ ] = new int [5] array? a) 5 X
4=20 b) 5 X 8=40 c) 5 X 2 =10 d) 5 X 1 =5
16. What specifies the position of an element in an array?
a) index b) serial c) number d) class
17. If we declare “int marks[ ]=new int [5];” array then what is its first and last
element?
a) First is marks[0] & Last is marks[4] b) First is marks[1] & Last is marks[5]
c) First is marks[4] & Last is marks[0] d) First is marks[5] & Last is marks[1]
18. Index value of an array always starts from ………………. number.
a) 0 (zero) b) 1 c) 2 d) 3
19. 1-D array is initialized using ……………sign to separate values of data elements in
…….braces.
a) , and { } b) ; and { } c) , and ( ) d) ; and ( )
20. Which of the following an example of data element of array?
a) int marks[ ]={90,70,77}; b) int marks[3]={90,70,77};
c) int marks[ ]=(90,70,77); d) int marks[ ]={90;70;77};
21. In java, we can not specify both the size of ……….. and ……….. values of the array
elements simultaneously while declaring an array.
a) dimensions b) initial c) class d) Both a and b
22.Various array static methods provided by Java in …………….. class.
a) java.util.Arrays b) java.util.Array c) java.io.Arrays d) java.util.io.Arrays
23.Which method to sort entire or part of array?
a) sort( ) b) Short( ) c) fill( ) d) unique( )
24. Which method is used to fill the whole or partial array with specified value?
a) fill( ) b) sort( ) c) put( ) d) short( )
25.If you want to assigns value 7 to all elements of list array then which method is
used?
a) fill (list, 7) b) fill (ls,7) c) sort(list,7) d) fill(7)
26.What will done with command “fill (list, 2,6,5);”.
a) Assigns array list value 5 to element list [2] to list[6-1]
b) Assigns array list value 6 to element list [2] to list[5-1]
c) Assigns array list value 5 to element list [5] to list[6-1] d) None of these
27.To search an element in an array then array class provides which method?
a) Linear search b) binarySearch( ) c) binary d) search()
28. Which method in Java, is used to search element by element comparison
in a serial fashion?
a) Linear search b) binarySearch( ) c) binary d) find()
29.Which of the following arrays are used to store tabular data in the form of rows
and columns?
a) 1D b) 2D c) single d) three dimension
30. If we write “int marks [ ][ ]=new int [5][3]” then which view shows the
elements of array in a table of 5 rows and 3 columns?
a) Logical view b) Physically view c) index view d) Display view
31. In Java, which view of array is stored in memory using contiguous memory?
a) Logical view b) Physically view c) index view d) Display view
32.In statement “int marks [ ][ ]=new int [5][3]” occupy how many memory?
a) 15 (53) integers that store 60 (154) bytes
b) 15 (53) integers that store 15 bytes c) 15 (53) integers that store 30 (152)
bytes d) 15 (53) integers that store 0 bytes
33. Java does not support …………….. type of an array.
a) 1D b) 2D c) multi-dimensional d) Both b and c
34. To initialize 2-D array, all these initialized rows are to be enclosed in ………….
braces.
a) Curly { } b) Square [ ] c) circle ( ) d) angular < >
35.In 2-D array all elements in curly braces are separated by ………….. sign.
a) comma (,) b) semicolon (;) c) colon( : ) d) dot (.)
36. Size of each row can be known using ……………… property of 1-D array.
a) length b) size c) width d) row
37.Declaring an array without …………….. does not create an array object.
a) initialization b) Declaration c) Instantiation d) None of these
38. 1-D array of characters can be considered as a……………..
a) integer b) character c) String d) long
39.Java supports two .types of strings that are handled by which of the following
class?
a) String b) StringBuffer c) character d) Both a and b
40. constructor is used without arguments create a string object with no
character.
a) String ( ) b) str( ) c) string( ) d) char()
41. Which type of constructor creates a string object with its initial values using
array argument?
a) String (char ary[ ]) b) String (char ary[ ], int start, int len)
c) String (String strObj) d) String (string literal)
42. Which of the following constructor creates a String object using 1-D array
argument starting at ary [start] with len number of character?
a) String (char ary[ ]) b) String (char ary[ ], int start, int len)
c) String (String strObj) d) String (string literal)
43. Which of the following constructor creates a String object which is same
as object specified in argument?
a) String (char ary[ ]) b) String (char ary[ ], int start, int len)
c) String (String strObj) d) String (string literal)
44. Which of the following constructor creates a String object that refers to
the literal specified in argument?
a) String (char ary[ ]) b) String (char ary[ ], int start, int len)
c) String (String strObj) d) String (string literal)
45. When two String objects are created using same string literals, memory
space is not allocated for …………….. object.
a) second b) first c) zero d) null
46. Separate memory is allocated when string objects are created using
………………..operator.
a) new b) obj c) static d) private
47.What happen when we create a String object st1 and st2 without using new
operator?
a) st1 and st2 refer to the same instance as created for st1.
b) Both st1 and st2 refer to different memory location.
c) Only st2 refer to different memory location.
d) Only st1 refer to different memory location.
48. What happen when we create a String object st1 and st2 using new
operator?
a) st1 and st2 refer to the same instance as created for st1.
b) Both st1 and st2 refer to different memory location.
c) Only st2 refer to different memory location.
d) Only st1 refer to different memory location.
49.In statement “String st1=new String(“I love India”);” what do we call st1?
a) Reference variable b) String object
c) String class d) character class
Chapter -9 Working with Array and String
5
50. In statement “String st1=new String(“I love India”);” what do we call “I love
India”?
a) String Object b) reference variable
c) string class d) character class
51. Which class provides methods to compare strings, find length of string,
combining strings, obtaining sub strings, converting strings, splitting strings,
searching for character or pattern in string etc?
a) String Class b) Character class c) Binary class d) bytecode clas
52.Which method returns an array of characters as byte from invoking string?
a) int length( ) b) byte [ ] getBytes( ) c) String(Bytes) d) getBytes( )
53.Which of the following string class method returns number of characters in
invoking string?
a) int length( ) b) int LENGTH( ) c) int Length( ) d) Float int length( )
54. Date and Calendar class is provided in which of the following package?
a) java.class b) java.util c) java.dc d) java.dateclass
55.Which class encapsulate both date and time and represents the value using
milliseconds precision?
a) Date b) Calendar c) date d) DATE
56. Which of the following Date method constructs Date object using current
system time?
a) Date (long ()) b) Date( ) c) Date (cur( )) d) Date [date()]
57.Which method returns a string representing date and time of invoking object?
a) long getTime( ) b) String toString( ) c) String( ) d) Date (Long ElapsedTime)
58. Which method sets new date and time of an object using elapsed time?
a) void setTime(long elapsedTime) b) long getTime( )
c) Date( ) d) Date(elapsed time)
59.Which method constructs Date object using specified time in milliseconds
elapsed since January 1, 1970 GMT?
a) Date (long elapsedTime) b) Date ( ) c) Date(time) d) Time(Date)
60. Which method returns nimber of milliseconds since January 1, 1970 GMT?
a) long getTime( ) b) String toString( ) c) Date( ) d) Date(Time)
61. Which class can be used to extract detailed calendar information like year,
month, minute etc.
a) Date class b) Calendar class c) calendar class d) CALENDAR class
62.Which is the subclass of Calendar class?
a) GregorianCalendar b) gregoriancalendar
c) cal d) calendargregorian
63. What is the set value of statement “calendar.set(Calendar.DATE,20);”?
a) set 20 as date of current month b) Set date to 20 of system month
c) set date above 20 of system month d) set date below 20 of system month
64. Which constant of Calendar class set day of calendar month?
a) DATE b) Date ( ) c) date ( ) d) Today()
65. Which constant of Calendar class set minutes?
a) Minute( ) b) MINUTE c) Min( ) d) minute( )
66. Which constant of Calendar class set seconds?
a) SECOND b) Second ( ) c) second( ) d) millisecond( )
67.Which constant of Calendar class set week number within the month?
a) WEEK_OF_MONTH b) WEEK.OF.MONTH
c) weekof month d) week-of-month
68. Which constant of Calendar class set week number within the year?
a) WEEK_OF_YEAR b) WEEK.OF.YEAR
c) weekofyear d) week-of-year
69.Which constant of Calendar class set day number in the year (1 for the first
day)?
a) DAY.OF.YEAR b) DAY_OF_YEAR c) day-of-year d) dayofyear
70.Which constant of Calendar class set Day number within a week (1 for Sunday, 7
for Saturday)?
a) DAY_OF_WEEK b) WEEK_OF_DAY c) week-of-week d) day-of-week
71. Which constant of Calendar class is similar as DATE constant?
a) DAY_OF_MONTH b) WEEK_OF_MONTH
c) day-of-month d) week-of-month
72.Method toString( ) returns answer in which data type?
a) char b) String c) int d) float
73.Method getTime( )returns answer in which data type?
a) long b) float c) int d) String
74.Which constant of Calendar class set 0 (Zero) for AM and 1 for PM?
a) AM.PM (b) AM_PM c) am_pm d) am.pm
75.In which format GregorianCalendar class constructor takes Date values?
a) MM-DD-YYYY b) YYYY-MM-DD c) YY-MM-DD d) MM-DD-YY
76.What is the output of statement “Date( );”?
a) Current system date and time b) Only date
c) Only time d) set date and time
77. If Today is “Tuesday” then what is the output of statement
“c1.get(Calendar.DAY_OFWEEK);”?
a) 3 b) 2 c) 1 d) 4
78.What is the output of statement “System.out.println(str1.equals(str2) );” if
content of srt1 and str2 is “India”?
a) True b) False c) Yes d) No
79.What is the size of second dimension in an array gseb [5] [3]?
a) 15 b) 3 c) 5 d) 18
80. Which of the following constructor is used for without argument create a
string object with no character?
a) String[ ] b) String{ } c) String ( ) d) String< >
81. Which of the following string class method returns true if invoking string is same
as str?
a) Boolean Equal (string str) b) Boolean equals ( String str)
c) Boolean eq (string str) d) Boolean Eq (string str)
82. Which of the following is useful to represent vector, matrix and other
multi- dimensional data?
a) Array b) Variable c) Element d) Tag
83. Which of the following refer to the starting index value in arrays?
a) 0 (zero) b) 1 c) null d) All of these
84. If int marks[ ] = {1,2,3,4,5); is defined in Java then what will be the value of
marks[3]?
a) 4 b) 3 c) 2 d) 5
85. Which of the following is not a right statement to declare an array named
marks in Java?
a) int marks[ ]=new int [3] b) int [ ] marks = new int[3]
c) int marks[3] = {50,60,70} d) int marks[ ]= {10,20,30}
86. In Java, which of the following methods of string class returns a string
after appending str with the invoking string?
a) char indexAt(int index) b) byte[ ] getBytes( )
c) String concat (String str) d) String append(String str)
87.In Java, if „str‟ is the object of string class and its content is @Thank GOD@,
then what is the value of str.length( )?
a) 9 b) 10 c) 11 d) 8
88. Which method of java.util.Arrays class is used to fill the whole or partial
array with specified value?
a) fill( ) b) sort( ) c) put( ) d) print( )
89.Which of the following symbol signifies the start and end of a JavaScript block?
a) semicolon b) square bracket c) curly bracket d) round bracket
90. In Java, int compareto(String str) method returns which value if invoking
string is equal to str?
a) 0 zero b) > 0 c) <0 d) -1