MCQ (Key Answer)
MCQ (Key Answer)
1. Which part of the class is invoked when any new object of the class is created?
a. New method b. constructor c. class definition d. first method of class
2. Identify the following operators |,*=,!=, ?:
a. Assignment, relational, ternary, logical
b. Relational, logical, assignment, ternary
c. Logical, assignment, relational, ternary
d. Logical , relational, ternary, assignment
3. The output for the following code is:
System.out.println(Math.pow(Math.ceil(Math.abs(-3.4)),Math.floor(3.8)));
a. 81.0 b. 64.0 c. 27.0 d. 8.0
4. Select the correct statement:
a. int []x=int[10];
b. String []names = new names[10];
c. float []f=new float[10];
d. Double []d=new double[10];
5. State the output:
System.out.println("CLOak".compareTo("CLOCK"));
a. 30 b.32 c.-30 d.-32
6. State the output:
System.out.println(Double.valueOf("1000")+("4.3678".indexOf('.')));
a. 10001 b. 1001.0 c. 10001.0 d. 10002.0
7. Arrays are passed by_____.
a. Call by value b. call by reference
8. “Glossary”.toUpperCase().substring(1,3) will return
a. GLOSSARY b. los c.LO d.LOS
9. trim() method is defined in package
a. java.util b. java.lang c. java.io d. java.String
12. The concept of having more than one constructor within a class is called as
a. Constructor Parsing b. Constructor overloading
c. Constructor Overriding d. Constructor Abstraction
14. Keyword used to specify the variable declared is common to all the objects.
a. static b. public c. this d. new
1
a. int b. double c. String
e. depends on the datatype of an array.
21. Assertion(A): Once the array is declared of n size it can store only n values not more than that.
Reason(R): Array index starts from 0 to n-1
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 true and Reason(R) is false.
d. Assertion(A) is false and Reason(R) is true.
22. The type of sorting method where the smallest value is interchanged with the first element is called as:
a. Bubble sort b. Selection sort c. quick sort d. insertion sort
2
28. Assertion(A): We explicitly not import java.lang package
Reason(R): java.lang is by default included into every program.
b. Both Assertion(A) and Reason(R) are true and Reason(R) is a correct explanation of
Assertion(A)
c. Both Assertion(A) and Reason(R) are true and Reason(R) is not a correct explanation of
Assertion(A)
d. Assertion(A) is true and Reason(R) is false.
e. Assertion(A) is false and Reason(R) is true.
32. The default value assigned to a String variable, by default constructor produced by java is:
a. “ ” b. null c. null character d. “0”
3
39. Output of the below code is:
int a[][] ={2,4,6,8}, {3,6,9,12}, {4, 10, 15, 20}};
System.out.println(a[2][1]);
a. 0 b. 10 c. 3 d. 9
38. Assertion(A): Constructors are used to initialize the data members of an object
Reason(R): Constructors do not return any value.
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 ofAssertion(A)
c. Assertion(A) is true and Reason(R) is false.
d. Assertion(A) is false and Reason(R) is true.
40. In call by _, changes done to formal parameters will reflect on actual parameters.
41. value b. reference c. in both d. none
46. Keyword that restricts the access only within the same class
a. private b. new c. this d. final
47. How many times will the following loop be executed and what will be the output?:
int n=10000;
while(n>100)
4
{
n=n/10 ;
}
System.out.println(n);
(a) 2 times, o/p-100
(b) 3 times, o/p-100
(c) 2 times, o/p-1000
(d) 1 time, o/p-1000
48. What will the following statement return?
“Knowledge is power”. substring(4). lastIndexOf(‘e’);
(a) 8
(b) 16
(c) 12
(d) 5
49. What will be the output of the following code?
String str[]={“Lilly”, “Hibiscus”, “Daffodil”, “Jasmine”};
System.out.println(str.length + str[2].length());
(a) 48
(b) 408
(c) 8
(d) 12