Q: Size of int in Java is
A: 32 bits
Q: What will be the output of the following program?
public class Main {
public static void main(String[] arg) {
Integer integer = new Integer(4);
System.out.print(integer.byteValue());
System.out.print("-");
int i = new Integer(4);
System.out.print(i.byteValue());
}
}
A: The code does not compile
Q: Java supports both primitive and non-primitive (user-defined) data types. Which one of the following is not a primitive datatype?
A: Class
Q: Of the types double, int, long, and short, how many could fill in the blank to have this code output 0?
static _____ defaultValue;
public static void main(String[] args) {
System.out.println(defaultValue);
}
A: 3
Q: Size of float and double in java is
A: 32 and 64
Q: What is the result of running this code?
public class Values
{
integer a = Integer.valueOf("1");
public static void main(String[] nums)
{
integer a = Integer.valueOf("2");
integer b = Integer.valueOf("3");
System.out.println(a + b);
}
}
A: The code does not compile.
Q: Which is the first line to trigger a compiler error?
public class Main
{
public static void main(String[] fruits)
{
double d1 = 5f; // p1
double d2 = 5.0; // p2
float f1 = 5f; // p3
float f2 = 5.0; // p4
}
}
A: p4
Q: What is the first line in the following code that does not compile?
public class Main
{
public static void main(String[] args)
{
int Integer = 0; // k1
Integer int = 0; // k2
Integer ++; // k3
}
}
A: k2
Q: Predict the output of the following code:
public class Main
{
public static void main(String[] args) {
final int a;
a = 5;
a = 10;
System.out.println(a);
}
}
A: Error: variable a might already have been assigned
Q: What will be the output of the following Java program?
class variable_scope
{
public static void main(String args[])
{
int x;
x = 5;
{
int y = 6;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y);
}
}
A: Compilation error
Q: Which one is not a valid statement in Java?I. double num = 2.718;II. double num = 2._718;III. double num = 2.7_1_8;
A: (II)
Q: What will be the output of the following Java program?
class leftshift_operator
{
public static void main(String args[])
{
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2);
System.out.print(i + " " + y);
}
}
A: 256 0
Q: Analyze the output for the following code:
public class Main
{
public static void main(String[] args) {
final int a;
a = 10;
System.out.println(a);
}
}
A: 10
Q: Analyze the output of the following.
public class Main
{
public static void main(String[] args)
{
final int a = 5;
a = 10;
System.out.println(a);
}
}
A: Error: Can't assign a value to final variable a
Q: Which statement is true about primitives?
A: Primitive types begin with a lowercase letter.