Java Multiple Choice Quiz - Technical Interview

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How many objects will be created in the following? String a = new String("Interviewbit"); String b = new String("Interviewbit"); Strinc c = "Interviewbit"; String d = "Interviewbit"; A. 2 B. 3 C. 4 D. None

B. 3 Using the new keyword creates an object everytime. Hence, 2 objects are created for first two statement. Next, a string is declared which creates another object. For the fourth statement, since, a string "Interviewbit" already exists, it doesn't create an additional object again. Hence, answer is 3.

Output of Math.floor(3.6) A. 3 B. 3.0 C. 4 D. 4.0

B. 3.0 floor returns largest integer that is less than or equal to the given number.

What is the implicit return type of constructor? A. No return type B. A class object in which it is defined C. void D. None

B. A class object in which it is defined Implicit return type of constructor is the class object in which it is defined.

Find the output of the following code. int ++a = 100; System.out.println(++a); A. 101 B. Compile error as ++a is not valid identifier C. 100 D. None

B. Compile error as ++a is not valid identifier

What is the variables declared in a class for the use of all methods of the class called? A. Object B. Instance variables C. Reference variable D. None

B. Instance variables

Select the valid statement. A. char[] ch = new char(5) B. char[] ch = new char[5] C. char[] ch = new char() D. char [] ch = new char[]

B. char[] ch = new char[5] char[] ch = new [5] is the correct syntax for declaring a character array.

Select the valid statement to declare and initialize an array. A. int[] A = {} B. int[] A = {1, 2, 3} C. int[] A = (1, 2, 3) D. int[][] A = {1, 2, 3}

B. int[] A = {1, 2, 3} is the valid way of declaring arrays.

Arrays in java are- A. Object references B. objects C. Primitive data type D. None

B. objects Arrays are objects in java. It is a container that holds a fixed number of items of a single type.

Identify the keyword among the following that makes a variable belong to a class, rather than being defined for each instance of the class. A. final B. static C. volatile D. abstract

B. static Static keyword makes a variable belong to a class, rather than being defined for each instance of the class.

Identify the return type of a method that does not return any value. A. int B. void C. double D. None

B. void void does not return any value

Total constructor string class have? A. 3 B. 7 C. 13 D. 20

C. 13 String class has 13 constructors.

Find the output of the following program. public class Solution{ public static void main(String[] args){ byte x = 127; x++; x++; System.out.print(x); } } A. -127 B. 127 C. 129 D. 2

A. -127 Range of byte data in java is -128 to 127. But the byte data type in java is cyclic in nature.

What is the size of float and double in Java? A. 32 and 64 B. 32 and 32 C. 64 and 64 D. 64 and 32

A. 32 and 64

Find the output of the following code. Public class Solution{ Public static void main(String... argos){ Int x = 5; x * = (3 + 7); System.out.println(x); A. 50 B. 22 C. 10 D. None

A. 50 Explanation - x* = 3 + 7 is equivalent to x * (3 + 7) = x * 10. Therefore, x = 50.

When is the object created with new keyword? A. At run time B. At compile time C. Depends on the code D. None

A. At run time The object created with new keyword during run-time.

When is the finalize() method called? A. Before garbage collection B. Before an object goes out of scope C. Before a variable goes out of scope D. None

A. Before garbage collection finalize() method is called before garbage collection.

Which of the following statements are true about finalize() method? A. It can be called Zero or one times B. It can be called Zero or more times C. It can be called Exactly once D. It can be calledOne or more times

A. It can be called Zero or one times

Find the output of the following code. if(1 + 1 + 1 + 1 + 1 == 5){ System.out.print("TRUE"); } else{ System.out.print("FALSE"); } A. TRUE B. FALSE C. Compile error D. None

A. TRUE Since, LHS matches RHS, hence the output is TRUE.

When an array is passed to a method, what does the method receive? A. The reference of the array B. A copy of the array C. Length of the array D. Copy of first element

A. The reference of the array

Exception created by try block is caught in which block A. catch B. throw C. final D. none

A. catch Answer- A) Exception created by try block is caught in catch block.

To which of the following does the class string belong to. A. java.lang B. java.awt C. java.applet D. java.string

A. java.lang

In which of the following is toString() method defined? A. java.lang.Object B. java.lang.String C. java.lang.util D. None

A. java.lang.Object toString() is defined in java.lang.Object

Where is System class defined? A. java.lang.package B. java.util.package C. java.io.package D. None

A. java.lang.package

Find the value of A[1] after execution of the following program. int[] A = {0,2,4,1,3}; for(int i = 0; i < A.length; i++){ A[i] = A[(A[i] + 3) % A.length]; } A. 0 B. 1 C. 2 D. 3

B. 1 a.length = 5 A[0] = a[(0 + 3) % 5] = a[3] = 1 So, a[0] = a[3] = 1 A[1] = a[(2 + 3) % 5] = a[0] = 1 Therefore, a[1] = 1;

Find the output of the following program. public class Solution{ public static void main(String[] args){ int[] x = {120, 200, 016}; for(int i = 0; i < x.length; i++){ System.out.print(x[i] + " "); } } } A. 120 200 016 B. 120 200 14 C. 120 200 16 D. None

B. 120 200 14 016 is on octal number, its equivalent decimal number is 14.

Automatic type conversion is possible in which of the possible cases? A. Byte to int B. Int to long C. Long to int D. Short to int

B. Int to long

What is Runnable? A. Abstract class B. Interface C. Class D. Method

B. Interface

Identify what can directly access and change the value of the variable res. package com.mypackage; public class Solution{ private int res = 100; } A. Any class B. Only Solution class C. Any class that extends Solution D. None

B. Only Solution class Only Solution class can directly access and change the value of the variable res.

What does the following string do to given string str1. String str1 = "Interviewbit".replace('e','s'); A. Replaces single occurrence of 'e' to 's'. B. Replaces all occurrences of 'e' to 's'. C. Replaces single occurrence of 's' to 'e'. D. None.

B. Replaces all occurrences of 'e' to 's' replace() replaces all the occurrences of the oldcharacter by the newcharacter.

Where does the system stores parameters and local variables whenever a method is invoked? A. Heap B. Stack C. Array D. Tree

B. Stack The system stores parameters and local variables in a stack.

Identify the incorrect Java feature. A. Object oriented B. Use of pointers C. Dynamic D. Architectural neural

B. Use of pointers Java does have the concept of pointers.

Identify the output of the following program. String str = "abcde"; System.out.println(str.substring(1, 3)); A. abc B. bc C. bcd D. cd

B. bc str.substring(start, end) returns the string from s[start] till s[end - 1]

How many times will "Interviewbit" be printed. Int count = 0; do{ System.out.println("Interviewbit"); count++; } while(count < 10); A. 8 B. 9 C. 10 D. 11

C. 10 Interviewbit will be printed 10 times, starting from count = 0.

Number of primitive data types in Java are? A. 6 B. 7 C. 8 D. 9

C. 8 (int, char, boolean, byte, long, float, short, double)

Identify the corrected definition of a package. A. A package is a collection of editing tools B. A package is a collection of classes C. A package is a collection of classes and interfaces D. A packed is a collection of interfaces

C. A package is a collection of classes and interfaces

compareTo() returns A. True B. False C. An int value D. None

C. An int value compareTo() returns an int value

Which of the following exception is thrown when divided by zero statement is executed? A. NullPointerException B. NumberFormatException C. ArithmeticException D. None

C. ArithmeticException ArithmeticException is thrown when divided by zero statement is executed.

Find the output of the following code. public class Solution{ public static void main(String[] args){ short x = 10; x = x * 5; System.out.print(x); } } A. 50 B. 10 C. Compile error D. Exception

C. Compile error *Lossy conversion from int to short

Identify the output of the following program. Public class Test{ Public static void main(String argos[]){ String str1 = "one"; String str2 = "two"; System.out.println(str1.concat(str2)); } } A. one B. two C. onetwo D. twoone

C. onetwo concat attached both the string. Hence answer is C.

Identify the output of the following program. String str = "Hellow"; System.out.println(str.indexOf('t)); A. 0 B. 1 C. true D. -1

D. -1 Since, t isn't present in the string str, it returns -1.

Find the output of the following code. int Interger = 24; char String = 'I'; System.out.print(Interger); System.out.print(String); A. Compile error B. Throws exception C. I D. 24 I

D. 24 I

Find the output of the following code. Public class Solution{ Public static void main(String args[]){ Int i; for(i = 1; i < 6; i++){ if(i > 3) continue; } System.out.println(i); } } A. 3 B. 4 C. 5 D. 6

D. 6 Since, the loop runs till 6, the value of i is 6.

Identify the infinite loop. A. for(; ;) B. for(int i = 0; i < 1; i--) C. for(int i = 0; ;i++) D. All of the above

D. All of the above

Identify the correct way of declaring constructor. Public class Solution {} A. Solution(){} B. public Solution(){} C. Solution(void){} D. Both (A) and (B)

D. Both (A) and (B) Both A and B are correct way of declaring constructor.

Identify the interface which is used to declare core methods in java? A. Comparator B. EventListener C. Set D. Collection

D. Collection Collection is used to declare core methods in java.

Identify the correct restriction on static methods 1. They must access only static data 2. They can only call other static methods. 3. They cannot refer to this or super. A. I and II B. II and III C. Only III D. I, II, III

D. I, II, III Static methods must only access static data and can call other static methods. Moreover they cannot refer this or super.

Which of the following is used to find and fix bugs in the program? A. JDK B. JRE C. JVM D. JDB

D. JDB

What does the operator >>>> do? A. Right shift operator B. Left shift operator C. Zero fill left shift D. Zero fill right shift

D. Zero fill right shift >>>> is Zero fill right shift.

Identify the prototype of the default constructor. Public class Solution {} A. Solution(void) B. Solution() C. public Solution(void) D. public Solution()

D. public Solution() public Solution() is the prototype of the default constructor.

Identify the modifier which cannot be used for constructor. A. public B. protected C. private D. static

D. static Static cannot be used for constructor.


Kaugnay na mga set ng pag-aaral

Physical Geology - Online Lab Quiz 06

View Set

CITI Quiz: Conflicts of Interest in Human Subjects Research

View Set

Study Guide Chapter 1.7 (Scale and Proportion)

View Set

Mental Health (Ch. 24 Questions)

View Set

1.4 processing and storage hardware

View Set

Chapter 27 Final Study Questions

View Set

EMT Chapter 27 - Face and Neck Injuries

View Set

Astronomy: Electromagnetic Spectrum

View Set