Data Types, Variables and Arrays
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;
a) 1 and 2
b) 2 and 3
c) 3 and 4
d) All statements are correct.
a) int
b) long
c) byte
d) float
-
class increment {
-
public static void main(String args[])
-
{
-
int g = 3;
-
System.out.print(++g * 8);
-
}
-
}
a) 25
b) 24
c) 32
d) 33
a) ASCII
b) ISO-LATIN-1
c) UNICODE
d) None of the mentioned
a) boolean b1 = 1;
b) boolean b2 = ‘false’;
c) boolean b3 = false;
d) boolean b4 = ‘true’
-
class array_output {
-
public static void main(String args[])
-
{
-
char array_variable [] = new char[10];
-
for (int i = 0; i < 10; ++i) {
-
array_variable[i] = 'i';
-
System.out.print(array_variable[i] + "" );
-
i++;
-
}
-
}
-
}
a) i i i i i
b) 0 1 2 3 4
c) i j k l m
d) None of the mentioned
-
class mainclass {
-
public static void main(String args[])
-
{
-
char a = 'A';
-
a++;
-
System.out.print((int)a);
-
}
-
}
a) 66
b) 67
c) 65
d) 64
-
class mainclass {
-
public static void main(String args[])
-
{
-
boolean var1 = true;
-
boolean var2 = false;
-
if (var1)
-
System.out.println(var1);
-
else
-
System.out.println(var2);
-
}
-
}
a) 0
b) 1
c) true
d) false
-
class booloperators {
-
public static void main(String args[])
-
{
-
boolean var1 = true;
-
boolean var2 = false;
-
System.out.println((var2 & var2));
-
}
-
}
a) 0
b) 1
c) true
d) false
a) malloc
b) alloc
c) new
d) new malloc
a) int arr[] = new int[5]
b) int [] arr = new int[5]
c) int arr[] arr = new int[5]
d) int arr[] = int [5] new
a) It is necessary to use new operator to initialize an array.
b) Array can be initialized using comma separated expressions surrounded by curly braces.
c) Array can be initialized when they are declared.
d) None of the mentioned
a) Row
b) Column
c) Both Row and Column
d) None of the mentioned
-
class array_output {
-
public static void main(String args[])
-
{
-
int array_variable [] = new int[10];
-
for (int i = 0; i < 10; ++i) {
-
array_variable[i] = i;
-
System.out.print(array_variable[i] + " ");
-
i++;
-
}
-
}
-
}
a) 0 2 4 6 8
b) 1 3 5 7 9
c) 0 1 2 3 4 5 6 7 8 9
d) 1 2 3 4 5 6 7 8 9 10
-
class multidimention_array {
-
public static void main(String args[])
-
{
-
int arr[][] = new int[3][];
-
arr[0] = new int[1];
-
arr[1] = new int[2];
-
arr[2] = new int[3];
-
int sum = 0;
-
for (int i = 0; i < 3; ++i)
-
for (int j = 0; j < i + 1; ++j)
-
arr[i][j] = j + 1;
-
for (int i = 0; i < 3; ++i)
-
for (int j = 0; j < i + 1; ++j)
-
sum + = arr[i][j];
-
System.out.print(sum);
-
}
-
}
a) 11
b) 10
c) 13
d) 14
-
class evaluate {
-
public static void main(String args[])
-
{
-
int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
-
int n = 6;
-
n = arr[arr[n] / 2];
-
System.out.println(arr[n] / 2);
-
}
-
}
a) 3
b) 0
c) 6
d) 1
a) The destination type is smaller than source type.
b) The destination type is larger than source type.
c) The destination type can be larger or smaller than source type.
d) None of the mentioned
byte b = 50;
b = b * 50;
a) b can not contain value 100, limited by its range.
b) * operator has converted b * 50 into int, which can not be converted to byte without casting.
c) b can not contain value 50.
d) No error in this code
a) long
b) int
c) double
d) float
a) Floating-point value assigned to an integer type.
b) Integer value assigned to floating type.
c) Floating-point value assigned to an Floating type.
d) Integer value assigned to floating type.
-
class conversion {
-
public static void main(String args[])
-
{
-
double a = 295.04;
-
int b = 300;
-
byte c = (byte) a;
-
byte d = (byte) b;
-
System.out.println(c + " " + d);
-
}
-
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300
-
class A {
-
final public int calculate(int a, int b) { return 1; }
-
}
-
class B extends A {
-
public int calculate(int a, int b) { return 2; }
-
}
-
public class output {
-
public static void main(String args[])
-
{
-
B object = new B();
-
System.out.print("b is " + b.calculate(0, 1));
-
}
-
}
a) b is : 2
b) b is : 1
c) Compilation Error.
d) An exception is thrown at runtime.
-
class c {
-
public void main( String[] args )
-
{
-
System.out.println( "Hello" + args[0] );
-
}
-
}
a) Hello c
b) Hello
c) Hello world
d) Runtime Error.
Answer Key will be mailed on Request
post a comment