This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQplus" Watch "JQplus" New topic
Author

JQplus

shabbir zakir
Ranch Hand

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

stevie
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?
Thanks.
Sajida
shabbir zakir
Ranch Hand

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

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.
stevie
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3285
    
    7
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


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JQplus