Data Types And Variables - Study Mode

[#86] What will the output of the following program? public class Test{
public static void main(String args[]){
float f = (1 / 4) * 10

int i = Math.round(f)

System.out.println(i)

}
}
Correct Answer

(B) 0

Explanation

Solution: The result of 1/4 will be zero because integer division is carried out on the operands. If you need to obtain a fractional value you need to use either a float or double literal as in 1F / 4F.

[#87] What is the output for the below code? class A{
int k

boolean istrue

static int p

public void printValue(){
System.out.print(k)

System.out.print(istrue)

System.out.print(p)

}
}
public class Test{
public static void main(String argv[]){
A a = new A()

a.printValue()

}
}
Correct Answer

(A) 0 false 0

Explanation

Solution: Global and static variable need not be initialized before use. Default value of global and static int variable is zero. Default value of boolean variable is false. Remember local variable must be initialized before use.

[#88] What will be the output of the following Java statement? class output {
public static void main(String args[])
{
double a, b,c

a = 3.0/0

b = 0/4.0

c=0/0.0

System.out.println(a)

System.out.println(b)

System.out.println(c)

}
}
Correct Answer

(D) all of the mentioned

[#89] What will be the output of the following Java code? class booloperators {
public static void main(String args[])
{
boolean var1 = true

boolean var2 = false

System.out.println((var1 & var2))

}
}
Correct Answer

(D) false

[#90] What will be the output of the following Java code? 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)

}
}
Correct Answer

(B) 39 44