Choose The Correct Answers: (C) Inheritance
Choose The Correct Answers: (C) Inheritance
(xvi) Go through the following text and choose the correct answer:
Selection statements help in selecting one alternative out of more than one options. They are also
called decision-making statements as the computer needs to take a decision while executing
these statements as per the conditions provided. The output of the program depends upon the
statement selected by the computer based on the validity of the condition.
Page 2 of 5
[20]
2. Choose the correct answers
(i)
(xi) Which of the following data types can have only one value at a time?
(a) Primitive
(b) Reference
(c) Abstract
(d) Import
Page 4 of 5
(c) return(s,p);
(d) return (4);
(xiii) What makes the two or more functions having the same name different?
(a) Number of arguments
(b) Type of arguments
(c) a&b
(d) All of the above
(xiv) Which of the following is a correct prototype of a function check which receives a
character ch and integer n and returns true or false?
(a) pubic int check( char ch,int n);
(b) public boolean chk(char ch, int n);
(c) public boolean check(char ch, integer n);
(d) public boolean check( char ch, int n);
(xv) Which type of the function increases the value of its return type by 1, each time the
function is called:
(a) Non-static function
(b) Static function
(c) Impure function
(d) None of the above
(xviii) The statement that converts the string object s=”400” to integer “s_int” is
................
(a) s_int=Integer.parse(s);
(b) s_int=Integer.Int(s);
(c) s_int=Integer.parseInt(s);
(d) s_int=integer.parseInt(s);
Page 5 of 5
(xix) The second last element of an array of size 100, has index:
(a) 97
(b) 99
(c) 98
(d) 100
(a) Encapsulation
(b) Inheritance
(c) Abstraction
(d) Polymorphism
(ii) How many bytes of memory will the following array use? double b[ ] = new double[6];
(a) 48 bytes
(b) 24 bytes
(c) 48 bits
(d) 24 bits
(iii) Give the output of the following statements:
String x[ ] = {"Apple", "Blueberry", "Grapefruit", "Tomato", "Watermelon"};
System.out.println(x[3].length());
(a) 10
(b) 5
(c) 6
(d) 9
Page 6 of 5
(iv) The output of Math.round(6.6) + Math.ceil(3.4) is:
(a) 9.0
(b) 11.0
(c) 10.0
(d) 11
(v) Which of the following is a valid Integer constant:
1. 4
2. 4.0
3. 4.3f
4. “four”
(a) Only 1
(b) 1 and 4
(c) 2 and 4
(d) 1 and 2
(vi) The _________ are the words which have special meaning
(a) Keywords (b) Identifier
(c) Methods
(d) Package
(vii) What is true about do while looping statement?
(a) do while statement executes the code of a loop at least once
(b) do while statement does not get execute if condition is not matched in the first iteration
(c) do while statement checks the condition at the beginning of the loop
(d) do while statement executes the code more than once always
(viii) What is the return type of a method that does not return any value?
(a) int
(b) void
(c) float
(d) null
(ix) Name the search algorithm which compares the sought key value with the key value of middle
element of the array at each stage.
(a) Bubble sort
(b) Linear search
(c) Binary search
(d) Selection sort
Observe the following code snippet and answer the questions (x) and (xi) switch (opn)
{ case 'a':
Page 7 of 5
System.out.println("Red"); break; case
'b':
System.out.println("Orange"); case 'c':
System.out.print("Blue"); break; default:
System.out.println("White");
}
(x) What will the output if opn= ‘A’?
(a) Red
(b) Orange
Blue
(c) White
(d) Blue
(xi) What will the code print if opn= ‘b’?
(a) Orange
Blue
(b) OrangeBlue
(c) Orange
(d) Blue
(xii) Which of the following statement contains an error?
(a) int a[]= int[10];
(b) float d[]={1,2,3};
(c) int a[]= {1,2}; int b[]; b=a;
(d) All the above
(xiii) How many values can return statement take back to the caller method?
(a) 0
(b) 1
(c) 2
(d) Many
(xiv) What will be the output of the following program?
int count = 1; while (count <= 15) {
System.out.println(count % 2 == 1 ? "***" : "+++++"); ++count;
} // end while
(a) 15 times ***
(b) 15 times +++++
(c) 8 times *** , 7 times +++++ (d) both will print only once
Page 8 of 5
(xv) Consider the following class: class Test { public static void swap(int i, int j) {
int temp=i;
i = j; j = temp;
}
public static void main(String[] args) { int i=10,j=20;
swap(i, j);
System.out.println("i = " + i + ", j = " + j);
}}
(a) i=10,j=20
(b) i=20,j=10
(c) i=10,j=10
(d) i=20,j=20
(xvi) Which of these jump statements can skip processing the remainder of the code in its body for a
particular iteration?
(a) break
(b) return
(c) System.exit(0)
(d) continue
(xvii) Assertion(A): Object is a instance of a class
Reason(R): A class describes the characteristics and behaviour that which is imbibed in its object.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a
correct explanation of Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false (xviii) Read the following text, and choose the
correct answer:
A two-dimensional array, also known as a 2D array, is a collection of data elements arranged in a
grid-like structure with rows and columns. Each element in the array is referred to as a cell and
can be accessed by its row and column indices/indexes. A 3X4 2D array typically stores 4
elements in each of the 3 rows.
How many elements will be stored in a 2D array of size 5X3
(a) 8 elements
(b) 20 elements
(c) 15 elements
(d) 35 elements
Page 9 of 5
(xix) Assertion(A): do while loop is executed atleast once even if it’s condition is false.
Reason(R): A do while loop tests condition before entering the loop body.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
(xx) Which of the following is correct way to initialize a 3X2 two-dimensional array?
(a) int dim[ ][ ] = {{1,2,3},{8,7,6}};
(b) int dim[ ][ ] = new int{{1,2,3},{8,7,6}};
(c) int dim[ ][ ] = {{1,2,3,8,7,6}};
(d) int dim[ ][ ] = {{1,2},{5,4},{8,7}};
Page 10 of
5
(vii) Which of the following is a keyword?
(a) token (b) continue (c) constant (d) all of these
(viii) Name the method used to convert String value into int?
(a) ParseInt() (b) parseInt() (c) parseInteger (d) none of
these
(ix) The ……… allows a class to use property of another class.
(a) Encapsulation (b) Abstraction (c) inheritance (d) None of these
(x) The ……… operator is used to access method of a class.
(a) Object (b) new (c) (.)dot (d) import
(xi) The statement System.out.println(1+2+“four ”+2+3); gives the output………
(a)3 four 5 (b)3 four 23 (c) 12 four 23 (d) error
(xii) x + = x++ + --x + --x + x; [ x = 5 ]
(a) 23 (b) 20 (c) 18 (d) none of these
(xiii) Math.pow(Math.ceil(4.22), Math.cbrt(8));
(a) 16 (b) 25 (c) 25.0 (d)16.0
(xiv) Consider the following String array and give the output:
String arr[ ]={"Java", "PHP", "Python", ".Net", "HTML"};
System.out.print( arr[2].charAt(2)+” “+arr[3].indexOf(‘N’));
(a) h -1 (b) H 1 (c) t 1 (d) Runtime Error
(xv) Predict the output of the following statement:
String wd[ ] = {"INDIA", "USA", "NEPAL", "GERMANY", "MEXICO"};
System.out.println(wd[2].substring(0,3) + wd[4].substring(4));
(a) USANY (b) MEXPAL (c) NEPCO (d) INDNY
(xvi) The return data type of Integer.parseInt( ) method is ________ .
(a) String (b) int (c) void (d) Integer
(xvii) Which of the following is not a type of inheritance?
(a) multiple (b) double (c) hybrid (d) single
(xviii) Corresponding wrapper class of the char data type is?
(a) String (b) Character (c) Char (d) CHARACTER
(xix) The process to change one data type value to another data type is known as
(a)Declaration (b)Type conversion (c) Converting data type (d)Initialising data type
Page 11 of
5
(iv) Which operator among the following is unary ?
(a) ! (b) ++ (c) -- (d) All of these
(v) a ____________ method needs to be called with the help of object
(a) void (b) class (c) static (d) nonstatic
(vi) *= is an example of _____ operator:
(a) logical (b) ternary (c) shorthand (d) assignment
(vii) What will be the result produced by the following statement ?
Math.ceil(8.4) + Math.pow(2,2);
(a) -13 (b) -9.45 (c) -7.75 (d) 13.0
(viii) Identify the error: System.out.println(max(4, 5));
(a) Syntax (b) Logical (c) Runtime (d) No error
Page 1 of 5
(xv) Assertion (A): When an array is initialised, its size is not specified.
Reason (R): The size of an array is equal to the number of elements in the list.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation
of Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
(xvii) An object that is created by explicit call to a constructor and preceded with the ‘new’ command is
termed as ______ object:
(a) Anonymous (b) Temporary (c) Explicit (d) Both a and b
Page 13 of
5