Java objective question
All the best important question
------------------------------------------------------------------------
1.
All the best important question
------------------------------------------------------------------------
1.
Answer: Illegal combination of final and abstract class
2.
Answer: 4
3.
Answer: error: bad operand types for binary operator '=='
System.out.println("Helo"+10==10);
4.
Answer: error: integer number too large
System.out.println(08);
Q5.
====
class Nit {
public static void main(String[] args) {
m1(2);
}
public static void m1(int i) {
if (i >= 0) {
m1(i - 1);
}
System.out.println(" " + i);
}}
output:
-1
0
1
2
==================================
Q.2
------
Question 2: What will be the output of this program:
public class nit1 {
public static void main(String args[]) {
int array[] = new int[10];
for (int i = 0; i < 10; ++i) {
array[i] = i;
System.out.print(array[i] + " ");
i++;
} }}
Output:
0,2,4,6,8
================================
Q.3
Question 3: What will be the output of this program:
public class Array {
public static void main(String args[]) {
int array[][] = new int[3][];
array[0] = new int[1];
array[1] = new int[2];
array[2] = new int[3];
int sum = 1;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < i + 1; ++j)
array[i][j] = j + 1;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < i + 1; ++j)
sum += array[i][j];
System.out.print(sum);
}
}
Output:
11
===============================
Q.4
Question 4: What will be the output of this program:
public class Array1 {
public static void main(String args[]) {
char array[] = new char[10];
for (int i = 0; i < 10; ++i) {
array[i] = 'i' + 5;
System.out.print(array[i] + "");
}}}
A) 1 2 3 4 5 6 7 8 9 10 B) 0 1 2 3 4 5 6 7 8 9 10
C) i i i i i i i i i i D)None Of These
Output: nnnnnnnnnnnnnnnnnnnnnn
==========================
Q.5
Question 5: What will be the output of this program:
import java.util.*;
public class array2 {
public static void main(String args[]) {
int[] inputArr = { 0, 10, 43, 27, 0, 59, 191, 0 };
int counter = 0;
for (int i = 0; i < inputArr.length; i++) {
if (inputArr[i] != 0) {
inputArr[counter] = inputArr[i];
counter++;
}}
while (counter < inputArr.length) {
inputArr[counter] = 0;
counter++;
}
System.out.println(Arrays.toString(inputArr));
}}
Output:
[10, 43, 27, 59, 191, 0, 0, 0]
Q.6
============================
Question 6: What will be the output of this program:
public class string {
public static void main(String[] args) {
String s1 = new String("hello");
String s2 = new String("helloW");
System.out.println(s1 = s2);
}}
A) True B)False C)HelloW D)hello
Output:
hellow
=================================
Question 7: What will be the output of this program:
public class string {
public static void main(String[] args) {
String s1 = new String("hello");
String s2 = new String(s2);
System.out.println(s1 == s2);
}
}
A) False B)True C) 0 D)CE
Output:
Variable s2 might be initialized Compile-time error
===============================
Question 8: What will be the output of this program:
public class string {
public static void main(String[] args) {
String s1 = "hello";
String s2 = "hello";
System.out.print(s1 == s2);
System.out.print(" " + s1.equals(s2));
}
A) False True B)False False C) True True D)True False
Output:
true true
==================================
Question 9: What will be the output of this program:
public class string {
public static void main(String[] args) {
String s1 = "hello";
String s2 = "hello";
System.out.print(s1.charAt(0) > s2.charAt(0));
}
}
A) False B)True C) 0 D)CE
Output:
False
==================================
Question 10: What will be the output of this program:
public class string {
public static void main(String[] args) {
String s1 = "hello";
int i2 = 9;
System.out.print(s1 + i2);
}
}
A) CE B)True C) False D)hello9 E)9hello
Output: hello9
Comments
Post a Comment