0% found this document useful (0 votes)
83 views5 pages

MCQ (Key Answer)

Uploaded by

shubh.luthra10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views5 pages

MCQ (Key Answer)

Uploaded by

shubh.luthra10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Four alternatives are given for each question.

Choose the most appropriate 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

10. “Examination”.substring(4); - returns the value :


a. i b. mination c. m d. ination

11. Math.ceil() returns type of value.


a. double b. int c. boolean d. char

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

13. Name the type of error in the following statement:


System.out.println(“Computer”.charAt(8));
a. Syntax error b. Run time error c. Logical error d. No error

14. Keyword used to specify the variable declared is common to all the objects.
a. static b. public c. this d. new

15. Index of an array are of datatype.

1
a. int b. double c. String
e. depends on the datatype of an array.

16. Output of the below code is:


int a[]=new int[10];
System.out.println(a[4]/a[2]);
a. 0 b. 1 c. Unknown value d. Error

17. “ends”.compareTo(“ends”); will result in


a. true b. false c. 1 d. 0

18. int a[]={4, 8, 12, 16};


System.out.println(++a[2] + --a[2]); will result in:
a. 24 b. 23 c. 25 d. 22
19. The least restricted access specifier is :
a. private b. public c. protected d. default

20. int a[][]={{2,4,6}, {3,5,7},{9,8,10}};


System.out.println(a[2][0]);
Will display:
a. 3 b. 4 c. 9 d. 6

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

23. Output of the following code is:


System.out.println(Math. abs(Math.floor(-38.5)));
a. 38.0 b. 39.0 c. -38.0 d. -39.0

24. Character.toUpperCase(‘=’) returns


a. false b. + c. = d. error

25. Integer.parseInt(“2023”.substring(2))+1; will result in:


a. 2024 b. 23 c. 24 d. 2023

26. An array can be created using keyword


a. int b. [] c. new d. array
27. Datatypes are of fixed size.
a. Primitive b. Composite c. Both a and b d. None

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.

29. Creating an object of a class using new keyword is called as


a. Initialization b. Iteration c. Instantiation d. Objectification

30. isDigit() method is present in class


a. String b. Character c. Integer d. Math

31. Which of the following is not true related to function overloading?


a. All the methods should have the same name
b. All the methods should have different parameter list.
c. All the methods should have different return type.
d. They should belong to the same class.

32. The default value assigned to a String variable, by default constructor produced by java is:
a. “ ” b. null c. null character d. “0”

33. “Experience”.substring(2, 6); - returns the value :


a. per b. peri c. perie d. xper

34. The following statement produces type of error


int a[]={2, 4, 6, ‘a ‘, 0 };
System.out.println(a[2]/a[4]);
a. Syntax error b. run-time error c. Logical error d. No error

35. The following variable reserves bytes of memory


int a[][]=new int[3][4]
a. 12 bytes b. 24 bytes c. 28 bytes d. 48 bytes

36. The following variable reserves bytes of memory.


short a[]=new short[15];
a. 15 bytes b. 30 bytes c. 60 bytes d. 120 bytes

37. Data type of values stored in an array are called as .


a. index b. elements c. base type d. subscript

38. Output of the below code is:


int a[]=new int[10];
System.out.println(a[4]*a[2]);
a. 0 b. 1 c. Unknown value d. Error

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

35. char ch[]={‘A’, ‘C’, 70, ‘D’};


System.out.println(ch[2]);will result in:
a. C b. F c. 70 d. E

36. int compute(int a, int b), here a and b are:


a. Instance variables b. class variables c. parameter variables d. local variables

37. int a[][]=new int[4][5] can store elements.


a. 4 b. 5 c. 9 d. 20

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.

39. Double.valueOf(a) converts to


a. String, Double b. double, String c. int, String d. double, int

40. In call by _, changes done to formal parameters will reflect on actual parameters.
41. value b. reference c. in both d. none

42. Character.isUpperCase(‘#’) returns


a. false b. true c. # d. error

43. Output for the following code is :


System.out.println(Math.pow(Math.max(-12, -5), Math.min(3, 4)));
a. -125.0 b. -625.0 c. 625.0 d. 1728.0

44. Local variable can be accessed only within


a. the methods in same class b. the method in which it is declared
b. the methods in same class and sub class d. the instance methods of the class

45. parameters given within the call of a function are called as :


a. Formal Parameters b. Actual parameters c. Local variables d. Instance variables

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

You might also like