class TestClass
{
public static void main(
String args[])
{
boolean b = false;
int i= 1;
do
{
i++;
}while(b = !b);
System.out.println(i);
}
}
What will be the result of attemting to compile this code. The options are
a) The code will fail to compile,while has an ivalid condition expression.
b) it will compile but will throw runtime exception.
c)it will print 3.
d) it will go in an infinite loop.
e) it will print 1.
The answer given is c. The answer is correct. But i
think it should be d.
Question ID : 953746506130
if write(0xAABBCCDD) is called on an instance of Outputstream, what will be written to the destination of the stream.
The correct answer given is the byte 0xDD.
i think the correct answer should be 0xAA.
Q.3)
Question ID :957672686580
Consider following two classes
package p1;
public class A
{
protected int i = 10;
public int getI() {return i;}
}
package p2;
import p1.*;
public class B extends p1.A
{
public void process(A a)
{
a.i = a.i *2;
}
public static void main(String args[])
{
A a = new B();
B b = new B();
b.process(a);
System.out.println(a.getI());
}
}
a.It will print 10.
b. it will print 20.
c. it will not compile.
d. it will throw an exception at RunTime.
e. None of the above.
THe answer given is c. I don't understand this answer. why should it give error.;
Q.4)
Which can hold a larger integer value,char or short?
the answer given is char. How come char when the range of both are equal
Q.5)
public class TestClass
{
static String str = "Hello World";
public static void changeIt(String str)
{
s = "Good bye world";
}
public static void main(String args[])
{
changeIt(str);
System.out.println(str);
}
}
this code prints out "Hello world" when it should be "Good bye World"
Q.6)
Given the following code,under which circumtances will the method return false.
public boolean
test(InputStream is) throws IOException
{
int value = is.read();
return value == (value & 0*ff);
}
The answer given is The end of the input was reached in the input stream. I don't understand this answer.
Which of the following statements are true?
a)The garbage collector informs when it is about to destroy it.
b) Garbage Collection feature of
java ensures that the program never runs out of memory.
the answer given is a. B is also true
Question ID: 957577484770
public class Conversion
{
public static void main(String args[])
{
int i = 12345678940;
float f = i;
System.out.println(f);
}
}
the options givbe are
a) it will print 0.
b) it will not print 0.
c) it will not compile.
d) it will throw an exception at runtime.
e) None of the above.
the answer given is b.First of all the code will not compile because of line 3. the int i is out of range.