File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JQplus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQplus" Watch "JQplus" New topic


shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183
class TestClass

public static void main(String args[])
boolean b = false;
int i= 1;
}while(b = !b);
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.
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();
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.;
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
public class TestClass
static String str = "Hello World";
public static void changeIt(String str)
s = "Good bye world";
public static void main(String args[])
this code prints out "Hello world" when it should be "Good bye World"
Given the following code,under which circumtances will the method return false.
public boolean test(InputStream is) throws IOException

int value =;
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;
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.
Stevie Kaligis
Ranch Hand

Joined: Feb 04, 2001
Posts: 400
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).

sajida kal
Ranch Hand

Joined: Mar 22, 2001
Posts: 89
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?
shabbir zakir
Ranch Hand

Joined: Nov 12, 2000
Posts: 183
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

Joined: Feb 04, 2001
Posts: 400
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.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3635
Just answered No. 6 here:
BTW, it's not 0*ff but 0xff
Get Certified, Guaranteed!
(Now Revised for the new Pattern)

Try out the world's only WebCompiler!

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I agree. Here's the link:
subject: JQplus
It's not a secret anymore!