permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes KHALID >>  MOCK  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "KHALID >>  MOCK  " Watch "KHALID >>  MOCK  " New topic
Author

KHALID >> MOCK

James Roddy
Greenhorn

Joined: Jan 16, 2001
Posts: 25
Hi All,
These Questions r 4rm KHALID's MOCK >>>>

Q.1.
The 8859-1 character code for the uppercase letter A is 65. Which of these code fragments declare and initialize a variable of type char with this value?
a. char ch=65;
b. char ch='\65';
c. char ch='A';
d. char ch="A";
Answer is given only (d) .But wht. is the problem with option (a) !!

Q.2.
Which statements concerning the effect of the statement
gfx.drawRect(5, 5, 10, 10)
are true, given that gfx is a reference to a valid Graphics object?
a. The rectangle drawn will have a total width of 5 pixels.
b. The rectangle drawn will have a total height of 6 pixels.
c. The rectangle drawn will have a total width of 10 pixels.
d. The rectangle drawn will have a total height of 11 pixels.
My choice is (c) , BUT ,the answer is given (d) !! W H Y !!!
Pls..explan me this answer. as per dawRect constructor the width should be 10 . then..where I am going wrong ?

Another Question(not related to above) I was thinking to ask that
'IS MATH CLASS IS IMMUTABLE like String or Wrapper class ? '

pleze,help me.
Thanks in advance.

Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974

Q.1.
The 8859-1 character code for the uppercase letter A is 65. Which of these code fragments declare and initialize a variable of type char with this value?
a. char ch=65;
b. char ch='\65';
c. char ch='A';
d. char ch="A";
Answer is given only (d) .But wht. is the problem with option (a) !!

Not only is there nothing wrong with a but d is incorrect. You can't initialize a char with a String. The correct answers are a and c.
------------------
Co-Moderator of the Programmer Certification Forums


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Q.2.
Which statements concerning the effect of the statement
gfx.drawRect(5, 5, 10, 10)
are true, given that gfx is a reference to a valid Graphics object?
a. The rectangle drawn will have a total width of 5 pixels.
b. The rectangle drawn will have a total height of 6 pixels.
c. The rectangle drawn will have a total width of 10 pixels.
d. The rectangle drawn will have a total height of 11 pixels.
My choice is (c) , BUT ,the answer is given (d) !! W H Y !!!
Pls..explan me this answer. as per dawRect constructor the width should be 10 . then..where I am going wrong ?

According to the API, "The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height."
So let's say x and y are 0 and the width and height are 10. Then the starting pixel of the rectangle will be 0 and the ending pixel will be 0 + 10 = 10. Counting from 0 to 10 gives 11 pixels.
------------------
Co-Moderator of the Programmer Certification Forums
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Another Question(not related to above) I was thinking to ask that IS MATH CLASS IS IMMUTABLE like String or Wrapper class ?
Immutable? You can't even instantiate the Math class!

------------------
Co-Moderator of the Programmer Certification Forums
Avinash Rai
Ranch Hand

Joined: Apr 26, 2001
Posts: 40
Originally posted by Thomas Paul:

Q.1.
The 8859-1 character code for the uppercase letter A is 65. Which of these code fragments declare and initialize a variable of type char with this value?
a. char ch=65;
b. char ch='\65';
c. char ch='A';
d. char ch="A";
Answer is given only (d) .But wht. is the problem with option (a) !!

Not only is there nothing wrong with a but d is incorrect. You can't initialize a char with a String. The correct answers are a and c.


Answer b is also correct.
I compiled it and the output was 5.
But I don't know why ch= '\65' gives output 5 ??
So option b is legal.

ratul banji
Ranch Hand

Joined: Mar 15, 2001
Posts: 108
BUT..Thomas .
The answer of q. 2 is little bit surprising.I am declearing the width as 10 ,,then


[This message has been edited by ratul banji (edited May 11, 2001).]
James Roddy
Greenhorn

Joined: Jan 16, 2001
Posts: 25
THANKS Thomas
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Avinash Rai:

Answer b is also correct.
I compiled it and the output was 5.
But I don't know why ch= '\65' gives output 5 ??
So option b is legal.
Legal? yes it is. The slash-6 is being taken as an escape character. However, the question specifically states which code fragments will "declare and initialize a variable of type char with this value [ i.e. uppercase 'A' ]". So b is not a correct choice.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by ratul banji:
BUT..Thomas .
The answer of q. 2 is little bit surprising.I am declearing the width as 10 ,,then
[This message has been edited by ratul banji (edited May 11, 2001).]

Yes, and strangely if you create a Rectangle object then width and height actually represent the width and height!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: KHALID >> MOCK
 
Similar Threads
AWT question from Khalid
drawRect()
awt question
questions from khalid's mock exam
Khalid's Exam