Q: What is the output of the following code snippet?
class Main
{
public static void main(String args[])
{
Integer int_data = new Integer(8);
System.out.print(int_data.byteValue());
System.out.print("-");
int int_data_2 = new Integer(8);
System.out.print(int_data_2.byteValue());
}
}
A: Compilation error
Q: What will be the output of the following Java code?
class box
{
int width;
int height;
int length;
}
class main
{
public static void main(String args[])
{
box obj = new box();
obj.width = 10;
obj.height = 2;
obj.length = 10;
int y = obj.width * obj.height * obj.length;
System.out.print(y);
}
}
A: 200
Q: What will this code print?
class test
{
int a;
int b;
void meth(int i , int j)
{
i *= 2;
j /= 2;
}
}
class Output
{
public static void main(String args[])
{
test obj = new test();
int a = 10;
int b = 20;
obj.meth(a , b);
System.out.println(a + " " + b);
}
}
A: 10 20
Q: Fill in the blanks to make the code compile.
public class Cat {
public String name;
public static void main(String[] meow) {
Cat cat = new Cat();
_____ = "Sadie";
}
}
A: cat.name
Q: What will be the output for the following code?
class Main
{
static int a = 3;
static int b;
static void meth(int x)
{
System.out.println("x = " + x);
System.out.println("a = " + a);
System.out.println("b = " + b);
}
static
{
System.out.println("Static block initialized.");
b = a * 4;
}
public static void main(String args[])
{
meth(42);
}
}
A: Static block initialized.x = 42a = 3b = 12
Q: What will be stored in the object obj in the following line of code ?
ItemType obj;
A: NULL
Q: Predict the output for the given code.
public class Main
{
private int a;
public Main(){
}
public Main(int temp){
a = -10;
}
public static void main(String[] args)
{
Main obj = new Main();
System.out.println(obj.a);
}
}
A: 0
Q: What are the class variables in the following program?
class IdentifyMyParts {
public static int x = 7;
public int y = 3;
}
public class Main {
public static void main(String [] args) {
IdentifyMyParts a = new IdentifyMyParts();
IdentifyMyParts b = new IdentifyMyParts();
a.y = 5;
b.y = 6;
a.x = 1;
b.x = 2;
System.out.println("a.y = " + a.y);
System.out.println("b.y = " + b.y);
System.out.println("a.x = " + a.x);
System.out.println("b.x = " + b.x);
System.out.println("IdentifyMyParts.x = " + IdentifyMyParts.x);
}
}
A: x
Q: How many instance initializers are in this code?
public class Bowling
{
{
System.out.println();
}
public Bowling ()
{
System.out.println();
}
static
{
System.out.println();
}
{
System.out.println();
}
}
A: 2
Q: Predict the output for the following code:
public class Main
{
public static int sum(int a, int b)
{
if(a+b>10)
return 0;
System.out.print(a+b);
return a+b;
}
public static void main(String[] args)
{
System.out.println(sum(1, sum(0,1)));
}
}
A: 122
Q: What should variable a's value be?
public class Main
{
public static void main(String[] args) {
int a;
System.out.println(a);
}
}
A: Compilation Error
Q: What is the output of this program?
class access
{
public int x;
static int y;
void cal(int a, int b)
{
x += a ;
y += b;
}
}
class static_specifier
{
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.y = 0;
obj1.cal(1, 2);
obj2.x = 0;
obj2.cal(2, 3);
System.out.println(obj1.x + " " + obj2.y);
}
}
A: 1 5
Q: What is the value of variable a in the following code?
public class Main
{
private int a;
public static void main(String[] args)
{
Main obj = new Main();
System.out.println(obj.a);
}
}
A: 0
Q: Predict the output of the following code:
public class Main
{
private int a;
public Main()
{
a = 10;
}
public static void main(String[] args)
{
Main obj = new Main();
obj.a = -10;
System.out.println(obj.a);
}
}
A: -10
Q: What is the output of this program?
class overload
{
int x; int y;
void add(int a)
{ x = a + 1; }
void add(int a , int b)
{ x = a + 2; }
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6, 7);
System.out.println(obj.x);
}
}
A: 8