• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JQplus

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1 : c
original b = false,
step 1 : perform the body,
step 2 : test loop-continuation (b = !b or b = !false), b become true
step 3 : perform the body,
step 4 : test loop-continuation (b = !b or b = !true), condition is false, stop execution.
Q2 : 0xDD
write() method only write bytes, if it takes an int as argument, it will truncates it down to the eight least significant bits before writing out as a byte.
Q3 : c (it will not compile)
i in a is protected, B is not implementing A

Q4 : char,
range char is 0 to 65535
range short is -32768 to 32767
Q5 : it won't compile
variabel "s" not found, but if i assume it str, the answer is "Hello World", becuase str = "Good bye World" is a local variabel

Q6 : me neither !!!
Q7 : answer is a
JVM not guarantee that GC will always executed, so your program still have a change to runs out of memory.
Q8 : you right it won't compile,
but if : int i = 1234567890 // your code is 12345678940
the answer is b (it will not print 0).

stevie
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stevie,
I have some doubts, hope you can clarify the same.
For question 1, in step 4, u have mentioned that the
condition becomes false. How is an assignment statement
evaluated as an expression in step 4, but not in step 2 ?
As for question 3, B extends class A, so it should have
access to protected member variable. I think the code
should compile and print 20. Could you explain this?
Thanks.
Sajida
 
shabbir zakir
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
Thanks Stevie a lot. But i don't your answer to question no.3
It will be great if you can give a detailed explanation. Thanks in advance
 
Stevie Kaligis
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A a = new B();
B b = new B();
In the different package, subclass can only access PROTECTED member in the superclass via references of it's own type (in this case b)
in other words :
Access is permitted to protected member of the superclass only by a REFERENCE of the SUBCLASS, Not by a reference of it's superclass.
so if the code (A a = new B()),A and B in the different package,there is no way reference "a" can access protected member of class A.
stevie
 
Enthuware Software Support
Posts: 4905
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just answered No. 6 here: http://www.jdiscuss.com/index.jsp?tab=discuss&pg=VP&fid=11&tid=1
BTW, it's not 0*ff but 0xff
HTH,
Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Try out the world's only WebCompiler!
www.jdiscuss.com
reply
    Bookmark Topic Watch Topic
  • New Topic