java question set 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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 22 B) 120 200 14 C) 120 200 16 D) 120 200 18 E) None of the above

B) 120 200 14

What is the size of float and double in Java? A) 16 and 32 B) 32 and 64 C) 64 and 128 D) 8 and 16 E) 24 and 48

B) 32 and 64

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

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

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

Arrays in Java are- A) Primitives B) Objects C) Strings D) Variables E) Constants

B) OBJECTS

What does the following string do to the 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' with 's'

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

B) bc

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

B) char ch = new char[5]

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}

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

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) Compile error D) 128 E) -128

B) -127

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

A) At run time

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

C) int value

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 E) 4

1

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

A) onetwo

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 package is a collection of interfaces

C) A package is a collection of classes and interfaces

Identify what can directly access and change the value of the variable res. A) Any class within the same package B) Any subclass of Solution C) Only Solution class D) Any class in Java E) Classes in other packages through import

C) Only Solution class

When an array is passed to a method, what does the method receive? A) Value of the array elements B) Size of the array C) Reference of the array D) Copy of the array E) None of the above

C) Reference of the array

Find the output of the following code. int Integer = 24; char String = 'I'; System.out.print(Integer); System.out.print(String); A) 24I B) I24 C) 24 73 D) 24 I E) None of the above

D) 24 I

In which of the following is the toString() method defined? A) java.util.ArrayList B) java.lang.Integer C) java.lang.StringBuilder D) java.lang.Object E) java.lang.System

D) java.lang.Object

Find the output of the following program. public class Solution { public static void main(String[] args) { short x = 10; x = x * 5;

Error

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. I and II II and III Only III I, II and III

I, II and III

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

Solution: A) -1

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) TRUEFALSEE) None of the above

Solution: A) TRUE

To which of the following does the class String belong to? A) java.lang B) java.util C) java.text D) java.io E) None of the aboveSolution: A) java.lang

Solution: A) java.lang

Identify the return type of a method that does not return any value. A) void B) null C) None D) empty E) non-void

Solution: A) void

Find the output of the following code. public class Solution{ public static void main(String... args){ int x = 5; x *= (3 + 7); System.out.println(x); } } A) 15 B) 50 C) 35 D) 25 E) 10

Solution: B) 50

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

Solution: C) 3

Number of primitive data types in Java are? A) 4 B) 6 C) 8 D) 10 E) 12

Solution: C) 8

Total number of constructors the String class has? A) 5 B) 7 C) 9 D) 11 E) 13

Solution: E) 13


Set pelajaran terkait

Chapter 13- Long-term Liabilities

View Set

Industrial Process: synthesis gas

View Set

Micro Chapter 14 (Mult Choice + TF) matching + (SA) Full multiple choice questions

View Set

Chemistry Chapter 6, Section 1 Review

View Set

Chapter 5 - The project manager, sponsor and other stakeholders

View Set