Your Seventh Vacation Assignment


Question 1

Question: Basic variable can store only one value. Such variable is known as __.
Options:
(A) constant variable
(B) scalar variable
(C) modular variable
(D) (A) or (B)

Answer: (B) scalar variable

Explanation: A scalar variable stores only a single value, unlike arrays or other complex data types that store multiple values.

Memory Tip: Scalar means single or simple.


Question 2

Question: What is an array?
Options:
(A) A collection of homogeneous type of elements
(B) A collection of different type of elements
(C) A collection representing different variables
(D) (A) or (C)

Answer: (A) A collection of homogeneous type of elements

Explanation: An array is a collection of elements that are all of the same data type.

Memory Tip: An array contains homogeneous elements (e.g., all integers, all strings).


Question 3

Question: Array can represent __ data.
Options:
(A) vector
(B) matrix
(C) multi-dimensional
(D) all of these

Answer: (D) all of these

Explanation: An array can represent 1D (vector), 2D (matrix), or multi-dimensional data structures.

Memory Tip: Arrays can represent vector, matrix, or higher dimensions depending on the requirement.


Question 4

Question: __ type of list can be stored in a 1-D array.
Options:
(A) Characters
(B) Numbers
(C) (A) and (B) both
(D) (A) or (B)

Answer: (C) (A) and (B) both

Explanation: A 1-D array can store a list of characters, numbers, or any other homogeneous data types.

Memory Tip: A 1-D array can store both characters and numbers, as long as the data type is consistent.


Question 5

Question: __ type of data can be stored in a 2-D array.
Options:
(A) Tabular
(B) Matrix
(C) (A) and (B) both
(D) (A) or (B)

Answer: (C) (A) and (B) both

Explanation: A 2-D array can represent tabular data or a matrix, as it consists of rows and columns.

Memory Tip: Tabular and matrix structures both fit into a 2-D array.


Question 6

Question: What is the index position in an array?
Options:
(A) Each element of an array
(B) Sequence of an array
(C) Value of each array element
(D) None of these

Answer: (B) Sequence of an array

Explanation: The index position is the sequence number assigned to each element in the array.

Memory Tip: The index is a number that tells you where each element of the array is stored.


Question 7

Question: __ is false about an array.
Options:
(A) Array is the word used to manage the list of things in Java.
(B) Array creation is the process of three steps.
(C) Array object can be created using two ways.
(D) When the same task is done for different elements, then an array is used.

Answer: (B) Array creation is the process of three steps.

Explanation: Array creation typically involves two steps: declaring the array and initializing the array.

Memory Tip: Array creation usually involves two steps: declaration and initialization.


Question 8

Question: How many steps are there to create an array?
Options:
(A) 2
(B) 3
(C) 4
(D) 5

Answer: (A) 2

Explanation: To create an array, you first declare it, and then you initialize it (with or without values).

Memory Tip: Array creation involves declaration and initialization.


Question 9

Question: How many ways can an array object be created?
Options:
(A) 3
(B) 4
(C) 2
(D) Only one

Answer: (C) 2

Explanation: An array object can be created in two ways: using the new keyword with a size, or by directly initializing it with values.

Memory Tip: Arrays can be created either by specifying the size or initial values.


Question 10

Question: __ method is used to create an array.
Options:
(A) Using new operator and defining its size
(B) To directly initialize the value to array elements.
(C) (A) or (B)
(D) (A) and (B) both

Answer: (C) (A) or (B)

Explanation: Arrays can be created either by using the new operator to define the size or by directly initializing the values.

Memory Tip: You can create an array either by defining the size or by directly initializing the values.


Question 11

Question: __ bracket is used to declare a 1-D array.
Options:
(A) ( )
(B) { }
(C) [ ]
(D) < >

Answer: (C) [ ]

Explanation: Square brackets [ ] are used in Java to declare an array.

Memory Tip: [ ] is the symbol for arrays in Java, indicating a collection of elements.


Question 12

Question: __ syntax is true to declare a 1-D array.
Options:
(A) [ ];
(B) [ ] ;
(C) (A) and (B) both
(D) [ ] {array name};

Answer: (C) (A) and (B) both

Explanation: Both of these syntaxes are correct ways to declare a 1-D array in Java. The brackets can either be placed after the data type or the array name.

Memory Tip: The correct placement of the square brackets can be either after the data type or after the array name.


Question 13

Question: __ is the wrong way to declare the marks array.
Options:
(A) int marks [ ] = int[5];
(B) int marks [ ] = new int [5];
(C) int [ ] marks = new int [5];
(D) All of these

Answer: (A) int marks [ ] = int[5];

Explanation: The correct syntax should use new int[5] or directly initialize the array. Option (A) is incorrect because it uses int[5] without the new keyword.

Memory Tip: To create an array, the correct way is to use new int[5] or direct initialization.


Question 14

Question: int marks[ ] = new int[5], then which is true about this array?
Options:
(A) Marks is the name of an array.
(B) Stores the five integer values.
(C) Indicates the indexes also.
(D) All of these

Answer: (D) All of these

Explanation: The array marks has a size of 5, stores five integer values, and has indexes (0 to 4).

Memory Tip: The array marks can store 5 integers and has index positions from 0 to 4.


Question 15

Question: How many bytes are used to store an integer value using the int data type?
Options:
(A) 2
(B) 4
(C) 8
(D) Only one

Answer: (B) 4

Explanation: In most systems, the int data type in Java takes 4 bytes to store an integer value.

Memory Tip: An int in Java typically uses 4 bytes of memory.


Question 16

Question: int marks[ ] = new int[5], how many bytes will be required by the marks array?
Options:
(A) 15
(B) 20
(C) 18
(D) 5

Answer: (B) 20

Explanation: An array of 5 integers, where each integer takes 4 bytes, will require 5 × 4 = 20 bytes.

Memory Tip: The memory required for an array is the size of each element times the number of elements.


Question 17

Question: What do we give in the [] after the array name?
Options:
(A) Index
(B) Subscript
(C) (A) or (B)
(D) None of these

Answer: (C) (A) or (B)

Explanation: Both index and subscript refer to the position of an element in an array. They are used interchangeably.

Memory Tip: The index or subscript tells you the position of an element in the array.


Question 18

Question: What is index or subscript?
Options:
(A) Location of element in the array
(B) Numerical content
(C) Textual content
(D) All of these

Answer: (A) Location of element in the array

Explanation: The index or subscript is the location of an element within an array, usually starting from 0.

Memory Tip: The index tells you where the element is located within the array.


Question 19

Question: Index value starts with __.
Options:
(A) 0
(B) 1
(C) -1
(D) 5

Answer: (A) 0

Explanation: In Java, the index of an array starts from 0.

Memory Tip: In Java, arrays are 0-indexed, meaning the first element is at index 0.


Question 20

Question: What does 2 suggest in marks[2]?
Options:
(A) Index of element
(B) Value of element
(C) Total elements
(D) All of these

Answer: (A) Index of element

Explanation: In the expression marks[2], the number 2 represents the index of the element.

Memory Tip: marks[2] refers to the element at index 2 in the marks array.


Question 21

Question: What will be the value of marks[3] in int marks[] = {90, 60, 70, 65, 80}?
Options:
(A) 70
(B) 65
(C) 3
(D) 80

Answer: (B) 65

Explanation: In the array {90, 60, 70, 65, 80}, the element at index 3 (starting from 0) is 65.

Memory Tip: Array indexing starts from 0, so marks[3] refers to the 4th element, which is 65.


Question 22

Question: What does marks[0] indicate?
Options:
(A) Value of marks variable is zero.
(B) Last element of array
(C) First element of array
(D) Such array variable is not possible

Answer: (C) First element of array

Explanation: marks[0] refers to the first element in the array, which is 90 in the given example.

Memory Tip: marks[0] refers to the first element, as arrays are 0-indexed in Java.


Question 23

Question: Elements in a 1-D array are separated using __.
Options:
(A) [ ]
(B) { }
(C) ( )
(D) < >

Answer: (B) { }

Explanation: The elements in an array are enclosed in curly braces { } when initialized.

Memory Tip: In array initialization, elements are enclosed by { }, like {90, 60, 70}.


Question 24

Question: __ syntax is not true for declaring the marks array.
Options:
(A) int marks[ ] = {90, 70, 77};
(B) int [ ] marks = {90, 70, 77};
(C) int [3] marks = {90, 70, 77};
(D) All of these

Answer: (C) int [3] marks = {90, 70, 77};

Explanation: The correct syntax does not specify the array size when initializing the array using { }. Option (C) is incorrect because the size of the array is specified along with initialization, which is unnecessary and syntactically wrong in Java.

Memory Tip: In Java, you can initialize an array without explicitly specifying the size.


Question 25

Question: If we initialize the values of variables directly, then __ operator is not needed.
Options:
(A) new
(B) create
(C) array name
(D) all of these

Answer: (A) new

Explanation: When initializing an array directly with values (e.g., int marks[] = {90, 70, 77}), you do not need the new keyword.

Memory Tip: The new keyword is required for dynamic array allocation but is not necessary when using direct initialization.


Question 26

Question: __ class method is used to display the value of array elements.
Options:
(A) println()
(B) printf()
(C) display()
(D) displayed()

Answer: (C) display()

Explanation: The display() method is commonly used in many classes to show array elements, though it’s not part of standard Java arrays. For built-in methods, println() is used to print values. However, the question may refer to a custom class method.

Memory Tip: While Java provides println() for output, custom classes may use display() to show array contents.


Question 27

Question: __ class method is given when an array is used in Java.
Options:
(A) Using private static
(B) Using public static
(C) Using protected static
(D) This is not possible

Answer: (B) Using public static

Explanation: In Java, static methods in the Arrays class (like Arrays.sort()) are defined with the public static access modifier.

Memory Tip: Array methods are typically public static in the java.util.Arrays class.


Question 28

Question: What cannot be given simultaneously while declaring the array in Java?
Options:
(A) Array name and size of dimension
(B) Size of dimension and initial values of elements
(C) Array name and number of elements
(D) Any of the above

Answer: (B) Size of dimension and initial values of elements

Explanation: You cannot specify both the size of the array and the initial values at the same time in the declaration. If you provide initial values, the size is inferred.

Memory Tip: Either specify the size of the array or provide initial values, not both.


Question 29

Question: What is the use of the static method provided by the java.util.Arrays class?
Options:
(A) Compare two arrays
(B) Find the particular element in the array
(C) Sort the array
(D) All of these

Answer: (D) All of these

Explanation: The Arrays class provides static methods like Arrays.equals() to compare arrays, Arrays.binarySearch() to find an element, and Arrays.sort() to sort an array.

Memory Tip: The java.util.Arrays class provides many useful methods for manipulating arrays.


Question 30

Question: Which elements are sorted by giving java.util.Arrays.sort(list1, 5)?
Options:
(A) list[1] to list[5]
(B) list[1] to list[5 – 1]
(C) list[0] to list[5 – 1]
(D) None of these

Answer: (B) list[1] to list[5 – 1]

Explanation: The Arrays.sort() method sorts a range of elements in an array, starting from the index 1 to 5 - 1 = 4, inclusive.

Memory Tip: The second parameter in Arrays.sort() specifies the ending index (exclusive), meaning it sorts from index 1 to 4.


Question 31

Question: To change the elements with some other values, __ method can be used.
Options:
(A) fill
(B) list
(C) sort
(D) full

Answer: (A) fill

Explanation: The fill() method in the java.util.Arrays class is used to fill all elements of an array with a specified value.

Memory Tip: The fill() method allows you to assign the same value to all elements in an array.


Question 32

Question: Which array elements are changed by giving java.util.Arrays.fill(list, 7)?
Options:
(A) All elements of the array are filled with 7.
(B) 7th element of the array is filled with 7.
(C) All elements after the 7th are filled with 7.
(D) Error message occurs.

Answer: (A) All elements of the array are filled with 7.

Explanation: The fill() method will replace all elements of the array with the specified value, which is 7 in this case.

Memory Tip: fill() affects all elements of the array.


Question 33

Question: java.util.Arrays.fill(list, 2, 6, 5) – Which elements will be filled with 5?
Options:
(A) list[2] to list[5]
(B) list[2] to list[6 – 1]
(C) list[2] to list[6]
(D) Error message occurs

Answer: (B) list[2] to list[6 – 1]

Explanation: The fill() method fills the elements starting from index 2 up to index 5 (as the ending index is exclusive).

Memory Tip: When using fill(), the ending index is exclusive, so list[2] to list[5] are filled with the value 5.


Question 34

Question: __ method is used to find a particular element in an array.
Options:
(A) binaryFind() method
(B) binarySearch() method
(C) display() method
(D) Search() method

Answer: (B) binarySearch() method

Explanation: The binarySearch() method is used to search for a particular element in a sorted array.

Memory Tip: binarySearch() works only on sorted arrays and returns the index of the element if found.


Question 35

Question: __ method can be used to compare the given value with each element of an array.
Options:
(A) Linear search
(B) Random search
(C) Only search
(D) Non-linear method

Answer: (A) Linear search

Explanation: A linear search compares the given value with each element in the array sequentially until a match is found or the end of the array is reached.

Memory Tip: Linear search checks each element one by one and is suitable for unsorted arrays.


Question 36

Question: When a particular element is searched using binarySearch() and if the element is not found, then __ value is returned.
Options:
(A) 0
(B) 1
(C) – 1
(D) error occurs

Answer: (C) – 1

Explanation: When binarySearch() does not find the element, it returns -1.

Memory Tip: binarySearch() returns -1 when the element is not present in the sorted array.


Question 37

Question: When a particular element is searched using binarySearch() and if the element is found, then __ value is returned.
Options:
(A) Index position of an element
(B) Value of an element
(C) Error message occurs
(D) 1

Answer: (A) Index position of an element

Explanation: If the element is found, binarySearch() returns the index position of the element in the array.

Memory Tip: binarySearch() returns the index of the found element.


Question 38

Question: How is the data stored in a 2-D array?
Options:
(A) In the form of rows and columns
(B) In a tabular form
(C) (A) and (B) both
(D) (A) or (B)

Answer: (C) (A) and (B) both

Explanation: A 2-D array stores data in rows and columns, which is effectively a tabular form.

Memory Tip: 2-D arrays are represented as matrices with rows and columns.


Question 39

Question: Pair of __ brackets are used to declare a 2-D array in Java.
Options:
(A) ( ) ( )
(B) [ ] [ ]
(C) { } { }
(D) < > < >

Answer: (B) [ ] [ ]

Explanation: In Java, a 2-D array is declared using two sets of square brackets: int[][] marks.

Memory Tip: A 2-D array uses [ ][ ] to indicate rows and columns.


Question 40

Question: How many values can be stored using int marks[][] = new int[5][3]?
Options:
(A) 5
(B) 3
(C) 15
(D) 20

Answer: (C) 15

Explanation: A 2-D array with dimensions [5][3] can store 5 * 3 = 15 values.

Memory Tip: The total number of elements in a 2-D array is the product of its dimensions.


Question 41

Question: Size of __ is indicated by the first bracket in int marks[][] = new int[5][3].
Options:
(A) rows
(B) column
(C) cell
(D) none of these

Answer: (A) rows

Explanation: In a 2-D array, the first bracket defines the number of rows. So in new int[5][3], the 5 represents the number of rows.

Memory Tip: The first dimension refers to rows, and the second to columns in a 2-D array.


Question 42

Question: Size of __ is indicated by the second bracket in int marks[][] = new int[5][3].
Options:
(A) rows
(B) column
(C) cell
(D) none of these

Answer: (B) column

Explanation: In a 2-D array, the second bracket defines the number of columns. In new int[5][3], the 3 represents the number of columns.

Memory Tip: The second dimension refers to columns.


Question 43

Question: How much size is occupied by the marks variable in int marks[][] = new int[5][3]?
Options:
(A) 15
(B) 60
(C) 5
(D) 3

Answer: (B) 60

Explanation: The total size occupied by the array depends on the number of elements and the size of each element. The array has 5 * 3 = 15 elements, and each int typically occupies 4 bytes. Therefore, the total size occupied is 15 * 4 = 60 bytes.

Memory Tip: The size of the array is the number of elements multiplied by the size of each element.


Question 44

Question: Maximum __ dimension can be given to make a 2-D array.
Options:
(A) [8][8]
(B) [255][255]
(C) [16][16]
(D) There is no limit

Answer: (D) There is no limit

Explanation: Java arrays can have large dimensions, and theoretically, there is no upper limit on the dimensions of a 2-D array, other than the limitations of memory.

Memory Tip: Java allows large arrays, but the system’s memory will eventually limit the array size.


Question 45

Question: In a 2-D array, a row is taken as __ array element.
Options:
(A) 1-D
(B) infinite
(C) 2-D
(D) multi

Answer: (A) 1-D

Explanation: In a 2-D array, each row is essentially a 1-D array. For example, in int[][] marks = new int[5][3], each row is a 1-D array with 3 elements.

Memory Tip: A row in a 2-D array is a 1-D array that holds data.


Question 46

Question: To give the initial values to each element in a 2-D array, the values separated by commas are given in __ brackets.
Options:
(A) [ ]
(B) ( )
(C) { }
(D) < >

Answer: (C) { }

Explanation: Initial values in a 2-D array are provided using curly braces { }. For example: int[][] marks = {{1, 2, 3}, {4, 5, 6}};.

Memory Tip: Curly braces { } are used for array initialization in Java.


Question 47

Question: To give the initial values to each element in a 2-D array, the values separated by __ are given in curly brackets.
Options:
(A) (,)
(B) (;)
(C) (:)
(D) (#)

Answer: (A) (,)

Explanation: In a 2-D array initialization, the values are separated by commas. For example: int[][] marks = {{1, 2, 3}, {4, 5, 6}};.

Memory Tip: Values in array initializations are separated by commas inside curly braces.


Question 48

Question: What is the meaning of ‘array within an array’ in Java?
Options:
(A) 1-D array
(B) Multi array
(C) 2-D array
(D) None of these

Answer: (C) 2-D array

Explanation: An “array within an array” refers to a 2-D array, where each element of the array is itself an array.

Memory Tip: A 2-D array is essentially an array of arrays.


Question 49

Question: Which property is used to count the number of elements in a 1-D array?
Options:
(A) total
(B) length
(C) totaldig
(D) number

Answer: (B) length

Explanation: The length property is used to get the number of elements in a 1-D array. For example, marks.length will give the number of elements in the array marks.

Memory Tip: The length property is used for both 1-D and 2-D arrays in Java.


Question 50

Question: What is the use of the length property in a 2-D array?
Options:
(A) Returns the number of rows.
(B) Returns the number of columns.
(C) Counts the length of a string.
(D) None of these

Answer: (A) Returns the number of rows.

Explanation: In a 2-D array, length gives the number of rows. To get the number of columns, you can use marks[0].length for the first row.

Memory Tip: For a 2-D array, length gives the number of rows, while the number of columns can be accessed from any row.


Question 51

Question: If the length property is used with the array name, then __ is displayed in the output.
Options:
(A) size of second dimension
(B) number of dimensions
(C) size of first dimension
(D) number of elements

Answer: (C) size of first dimension

Explanation: The length property, when used with an array name, returns the size of the first dimension (the number of rows in a 2-D array or the number of elements in a 1-D array).

Memory Tip: For a 2-D array, length gives the number of rows, while the length of a specific row can be accessed through array[0].length (number of columns).


Question 52

Question: Array size can be mentioned in __ brackets.
Options:
(A) { }
(B) < >
(C) []
(D) ( )

Answer: (C) []

Explanation: In Java, array sizes are specified using square brackets [], like int[] marks = new int[5];.

Memory Tip: Arrays in Java always use square brackets to define their size and type.


Question 53

Question: Position of index starts with __.
Options:
(A) 0
(B) – 1
(C) 1
(D) 2

Answer: (A) 0

Explanation: In Java, array indices start at 0. The first element of an array is accessed with index 0.

Memory Tip: Remember, in most programming languages (including Java), array indices are zero-based.


Question 54

Question: What is a string?
Options:
(A) One type of a character
(B) Series of characters
(C) Special type of character
(D) None of these

Answer: (B) Series of characters

Explanation: A string in Java is a sequence or series of characters. For example, "Hello" is a string consisting of the characters ‘H’, ‘e’, ‘l’, ‘l’, ‘o’.

Memory Tip: A string is always enclosed in double quotes (" ").


Question 55

Question: Strings are enclosed in __ brackets.
Options:
(A) double quotes
(B) single quotes
(C) curly
(D) square

Answer: (A) double quotes

Explanation: In Java, strings are enclosed in double quotes, like "Hello World".

Memory Tip: Single quotes are used for characters, while double quotes are used for strings.


Question 56

Question: Which statement is false related to strings in Java?
Options:
(A) Group of characters means a string
(B) There are three types of strings in Java.
(C) Strings are controlled using the classes like ‘String’ and ‘StringBuffer’
(D) Strings are enclosed in double quotes

Answer: (B) There are three types of strings in Java.

Explanation: This statement is false because there are two primary types of strings in Java: String (immutable) and StringBuffer (mutable).

Memory Tip: Java has two classes to handle strings: String (immutable) and StringBuffer (mutable).


Question 57

Question: __ constructor will create a string object without any character.
Options:
(A) String (char ary[])
(B) String()
(C) String (String strobj)
(D) String (String literal)

Answer: (B) String()

Explanation: The String() constructor creates an empty string object, which means it does not contain any characters. For example, String str = new String(); creates an empty string.

Memory Tip: The String() constructor is used for creating an empty string object.


Question 58

Question: Which constructor will create a string object using the variable’s initial value?
Options:
(A) String (char ary[])
(B) String()
(C) String (String String)
(D) String (String literal)

Answer: (A) String (char ary[])

Explanation: The String(char ary[]) constructor is used to create a string object using a character array. For example: String str = new String(name); where name is a character array.

Memory Tip: This constructor converts a character array into a string.


Question 59

Question: char name[] = {'S', 'A', 'N', 'J', 'Y'}; String str = new String(name, 1, 3); System.out.println(str);
What will be the output?
Options:
(A) SAN
(B) ANJ
(C) NIY
(D) SJY

Answer: (B) ANJ

Explanation: The String(char[] value, int offset, int count) constructor creates a string by taking a substring from the character array. It starts at index 1 and takes 3 characters: 'A', 'N', 'J'.

Memory Tip: The offset parameter is where the substring begins, and count is the number of characters to take.


Question 60

Question: If String str = "Divyakant Sir";, then which of the following constructors can create the same string object as str?
Options:
(A) String()
(B) String(String strObj)
(C) String(String literal)
(D) String(char ary[])

Answer: (B) String(String strObj)

Explanation: The constructor String(String strObj) creates a string object from an existing string (string literal or string object). So, new String("Divyakant Sir") will create the same string object as str.

Memory Tip: The String(String strObj) constructor creates a string from another string.


Question 61

Question: Each character occupies __ bytes in Java.
Options:
(A) 2
(B) 4
(C) 6
(D) 1

Answer: (A) 2

Explanation: In Java, each character in a string or char variable occupies 2 bytes, because Java uses Unicode encoding to represent characters, which requires 2 bytes for each character.


Question 62

Question: __ data type should be used instead of char to include a character using less space.
Options:
(A) String
(B) Character
(C) bytes
(D) number

Answer: (C) bytes

Explanation: The byte data type is used for storing data in a more compact format, typically 1 byte per value. In contrast, char uses 2 bytes. For space efficiency, byte should be used if only the raw byte values are required, but note that byte cannot directly store a character like char.


Question 63

Question: If two strings are the same, then using __ operator different locations are assigned in the memory.
Options:
(A) create
(B) new
(C) CREATE
(D) Set

Answer: (B) new

Explanation: When two string objects are created using the new keyword, even if the content is the same, they will be assigned to different memory locations because the new operator explicitly creates a new object, bypassing the string pool optimization.


Question 64

Question: If two string objects are created using the same string literal, then what is done for the second object by the memory?
Options:
(A) Does not allocate space
(B) Allocates double space
(C) Allocates space
(D) Nothing is done

Answer: (A) Does not allocate space

Explanation: When a string object is created using a string literal, Java checks the string pool. If the string already exists in the pool, it reuses the same object. So, memory is not allocated again for the same literal string.

Memory Tip: String literals are stored in a special memory area called the string pool to save memory and improve performance.


Question 65

Question: __ is the facility of the string class method.
Options:
(A) To compare two strings
(B) To get the length of strings
(C) To concatenate two strings
(D) All of these

Answer: (D) All of these

Explanation: The String class in Java provides methods for comparing strings (equals()), getting the length of a string (length()), and concatenating strings (concat()).


Question 66

Question: If the string and parameter str (object) are the same, then __ value is returned.
Options:
(A) True
(B) False
(C) Wrong
(D) Error

Answer: (A) True

Explanation: The equals() method of the String class returns true if the string and the parameter object are the same in terms of content (i.e., they contain the same characters).


Question 67

Question: If the method-calling string object is the same as the parameter str, then __ value is returned.
Options:
(A) – 1
(B) 0
(C) 1
(D) < 0

Answer: (B) 0

Explanation: The compareTo() method of the String class returns 0 if both strings are equal (i.e., they have the same characters in the same order).


Question 68

Question: __ method is not provided by the string class.
Options:
(A) To get the number of words
(B) To divide the string into substrings
(C) To separate some part of a string
(D) To append the string at the end of another string

Answer: (A) To get the number of words

Explanation: Java’s String class does not provide a direct method to count the number of words. You would have to manually split the string and count the parts. Methods like split() are used to divide strings, but counting words is not directly supported by the class itself.


Question 69

Question: __ method is provided by the string class.
Options:
(A) To convert the characters of a string to uppercase or lowercase.
(B) String or its part to be copied
(C) To convert the string to a byte array.
(D) All of these

Answer: (D) All of these

Explanation: The String class provides methods for all of the above functionalities:

  • toUpperCase() and toLowerCase() convert the string to uppercase or lowercase, respectively.
  • substring() can be used to copy parts of the string.
  • getBytes() converts a string to a byte array.

Question 70

Question: __ method returns the number of characters lying in the string object.
Options:
(A) int len()
(B) int length()
(C) int count()
(D) int encount()

Answer: (B) int length()

Explanation: The length() method returns the number of characters in a string object.

Memory Tip: length() is a method of the String class that returns the number of characters in the string, not to be confused with len() which is used in some other languages.


Question 71

Question: __ method converts the characters of an array to the byte array.
Options:
(A) byte [ ]
(B) getBytes [ ]
(C) byte [ ] getBytes [ ]
(D) getBytes()

Answer: (D) getBytes()

Explanation: The getBytes() method is used to convert a string to a byte array in Java. It is a method of the String class that returns the byte representation of the string.


Question 72

Question: __ method converts all the characters of a string to lowercase characters.
Options:
(A) LowerCase()
(B) String toLowerCase()
(C) String toLowercase [ ]
(D) lowercase()

Answer: (B) String toLowerCase()

Explanation: The correct method to convert all characters of a string to lowercase is toLowerCase(). It is a method of the String class.


Question 73

Question:

String str = "Saraswati Vidhyalaya";
System.out.println(str.length());

What will be the output of this program?
Options:
(A) 18
(B) 19
(C) 20
(D) 21

Answer: (B) 19

Explanation: The string “Saraswati Vidhyalaya” contains 19 characters, including the space between the two words. The length() method of the String class returns the number of characters in the string.


Question 74

Question: What is the meaning of length for an array variable?
Options:
(A) Method
(B) Attribute
(C) Properties
(D) (B) or (C)

Answer: (D) (B) or (C)

Explanation: For an array variable in Java, length is an attribute (or property). It is not a method, but a field that directly gives the size of the array (i.e., the number of elements in the array).


Question 75

Question: What is the meaning of length for a string object?
Options:
(A) Method
(B) Attribute
(C) Function
(D) Properties

Answer: (A) Method

Explanation: For a string object, length is a method, not an attribute. The length() method returns the number of characters in the string.


Question 76

Question: Which method is not available for the String class in Java?
Options:
(A) To cut some part of the string
(B) To get the particular character for the given index position
(C) To reverse the string
(D) To divide the string into substrings

Answer: (C) To reverse the string

Explanation: The String class does not have a built-in method to reverse a string directly. To reverse a string, you would typically use StringBuilder or StringBuffer with the reverse() method. The other options are available in the String class (substring() for dividing, charAt() for getting a character).


Question 77

Question: The Date class facility is available in the __ package of Java.
Options:
(A) java.utilities
(B) java.char
(C) java.util
(D) java.prop

Answer: (C) java.util

Explanation: The Date class is part of the java.util package in Java, which provides date and time functionality.


Question 78

Question: __ method can create a Date object using the current time of the system.
Options:
(A) Date[ ]
(B) Date()
(C) Time()
(D) Time[ ]

Answer: (B) Date()

Explanation: The Date() constructor creates a Date object initialized with the current date and time based on the system’s clock.


Question 79

Question: __ package has the feature of using the Calendar class.
Options:
(A) java.lib.util
(B) java.util
(C) java.utilities
(D) jav.libprop

Answer: (B) java.util

Explanation: The Calendar class is part of the java.util package in Java. It is used for date and time manipulation, providing more functionality than the Date class.


Question 80

Question: __ subclass of the Calendar class is used in our syllabus.
Options:
(A) GeoCalendar
(B) GregorianCalendar
(C) StandardCalendar
(D) MainCalendar

Answer: (B) GregorianCalendar

Explanation: The GregorianCalendar class is a subclass of the Calendar class and is the one commonly used to work with dates and times in the Gregorian calendar system, which is the most widely used calendar system today.


Question 81

Question: Since __ total milliseconds are returned by the getTime() method.
Options:
(A) January 1, 1990 GMT
(B) January 1, 1980 GMT
(C) January 1, 1970 GMT
(D) January 26, 1947 GMT

Answer: (C) January 1, 1970 GMT

Explanation: The getTime() method in Java returns the number of milliseconds since January 1, 1970 GMT, also known as the Unix epoch.


Question 82

Question: Using __ method of the Calendar class, we can set the field constants.
Options:
(A) Set
(B) get
(C) set
(D) Get

Answer: (C) set

Explanation: The set() method of the Calendar class is used to set the value for a specific field (like date, year, or month) in the calendar.


Question 83

Question: If the calendar is the object of the Calendar class, then __ date is set by giving calendar.set(Calendar.DATE, 20).
Options:
(A) 10
(B) 20
(C) 30
(D) 1

Answer: (B) 20

Explanation: The set() method with Calendar.DATE sets the date to 20. So, the 20th day of the month is assigned as the date.


Question 84

Question: __ is a variable representing a collection of homogeneous type of elements.
Options:
(A) Arrangement
(B) Array
(C) Assortment
(D) Group

Answer: (B) Array

Explanation: An array is a collection of elements of the same type stored in contiguous memory locations.


Question 85

Question: __ is used to represent two-dimensional (2-D) data structures like tables or rows and columns.
Options:
(A) Vector
(B) Path
(C) Matrix
(D) Route

Answer: (C) Matrix

Explanation: A matrix is a two-dimensional data structure, often used to represent tables or grids with rows and columns.


Question 86

Question: Array with __ dimension is known as a 1-D array.
Options:
(A) double
(B) triple
(C) (A) and (B) both
(D) single

Answer: (D) single

Explanation: A 1-D array is a single-dimensional array, where the data is stored in a single row or list.


Question 87

Question: Instead of declaring individual variables like marks1, marks2, marks3, marks4, marks5; one can declare an array __.
Options:
(A) marks[5]
(B) mark[5]
(C) marksf 1-5]
(D) All of these

Answer: (A) marks[5]

Explanation: Instead of creating separate variables for each mark, an array like marks[5] can be used to store multiple values of the same type.


Question 88

Question: Individual variable elements of an array marks[5] can be accessed as __.
Options:
(A) marks[1], marks[2], marks[3], marks[4], marks[5]
(B) marks[-1], marks[1], marks[2], marks[3], marks[4]
(C) marks[0], marks[1], marks[2], marks[3], marks[4]
(D) marks[-1], marks[0], marks[1], marks[2], marks[3]

Answer: (C) marks[0], marks[1], marks[2], marks[3], marks[4]

Explanation: In an array marks[5], the valid indices are from 0 to 4. The first element is accessed with marks[0], and the last with marks[4].


Question 89

Question: For example, to store the marks obtained by a student in five tests in Mathematics, an array of __ integer elements can be used.
Options:
(A) five
(B) six
(C) four
(D) seven

Answer: (A) five

Explanation: To store marks in five tests, you need an array of size five.


Question 90

Question: The array variable marks[5] has an index value from __.
Options:
(A) 1 to 5
(B) 0 to 4
(C) 0 to 5
(D) 1 to 4

Answer: (B) 0 to 4

Explanation: For an array declared as marks[5], the valid indices are from 0 to 4, since the index in Java is zero-based.


Question 91

Question: In the array variable marks[5], marks[0] refers to the __ element.
Options:
(A) last
(B) second
(C) first
(D) none of these

Answer: (C) first

Explanation: In a zero-based array, marks[0] refers to the first element of the array.


Question 92

Question: The array size is same as the number of values specified in __.
Options:
(A) braces
(B) index
(C) default value
(D) initialization

Answer: (A) braces

Explanation: The size of an array is determined by the number of elements defined inside the braces during initialization.


Question 93

Question: Methods sort() and fill() are part of __ class.
Options:
(A) Java.Arrays
(B) java.util
(C) java.util.Arrays
(D) All of these

Answer: (C) java.util.Arrays

Explanation: The methods sort() and fill() are part of the java.util.Arrays class, which provides utility methods for working with arrays.


Question 94

Question: int marks[][] = new int[5][3];, the logical view of array elements is a table of __.
Options:
(A) 3 rows and 5 columns
(B) 15 columns
(C) 5 rows and 3 columns
(D) 15 rows

Answer: (C) 5 rows and 3 columns

Explanation: The array marks[5][3] has 5 rows and 3 columns, forming a 2D matrix.


Question 95

Question: A 1-D array of __ can be considered as a string.
Options:
(A) spaces
(B) groups
(C) characters
(D) columns

Answer: (C) characters

Explanation: A 1-D array of characters can be treated as a string.


Question 96

Question: String() without arguments creates a __ object with no character.
Options:
(A) string
(B) character
(C) buffer
(D) code

Answer: (A) string

Explanation: The String() constructor without arguments creates an empty String object.


Question 97

Question: To save space, if the characters are __, an array of bytes should be used instead of an array of characters.
Options:
(A) ASCII
(B) coded
(C) ACSII
(D) ACIIS

Answer: (A) ASCII

Explanation: If the characters are in ASCII format, using an array of bytes is more space-efficient compared to using an array of characters.


Question 98

Question:

String str1 = "Divyakant Sir";  
String str2 = "Sanjay Sir";  
System.out.println(str1.compareTo(str2));  


What will be the output of this program?
Options:
(A) 0
(B) >0
(C) < 0
(D) None of these

Answer: (C) < 0

Explanation: The compareTo() method compares two strings lexicographically. Since "Divyakant Sir" is alphabetically less than "Sanjay Sir", it returns a negative value, hence the output will be < 0.


Question 99

Question: Method void ______ copies characters of the invoking string from fromIndx to toIndx-1 to the target array from targetIndx onwards.
Options:
(A) toUpperCase()
(B) toLowerCase()
(C) concat(String str)
(D) getChars(int fromIndx, int toIndx, char target[], int targetIndx)

Answer: (D) getChars(int fromIndx, int toIndx, char target[], int targetIndx)

Explanation: The getChars() method copies a substring from the invoking string to the specified position in a target character array.


Question 100

Question: With an array variable, length is an __ or property of the array.
Options:
(A) attribute
(B) method
(C) string
(D) none of these

Answer: (A) attribute

Explanation: The length of an array is an attribute (or property) that indicates the number of elements in the array.

Leave a Reply

Your email address will not be published. Required fields are marked *