• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Some mock ?'s

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like a few clarifications on the following mock questions
Select valid arrays declarations or initializations (Select 3)
a) int a[] = new int[5];
b) Double d = new double[4];
c) Char []c = "Element";
d) Object obj = new double [8];
e) int ab[][] = {0,1,2} {1,5,6}
f) int []q = {1,2,3}
Now I didn't think there was three valid since a, f and I think b,c,d are in the wrong form and that leaves f but there is no semi colon on the end of the line and also there is no comma separating the two array groups. Are these things not needed for some reason?
2) What can the throw statement throw? (select 4)
a) Error
b) Event
c) RunTimeException
d) Object
e) Exception
f) Throwable
Now here I am thinking a, c, e, and f since these are all derivations of error handling.
[Third question deleted because it turns out to be extremetly similar to a real exam question (though Ian didn't know that) - Jim Yingst]
Thanks,
Ian

[This message has been edited by Jim Yingst (edited March 31, 2001).]
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first question:
D should be the correct answer! B.C,E are obviously wrong, so the answer should be: A,D,F
Second qustion:
I agree with you.
It is A,C,E,F.
[This message has been edited by ego hu (edited March 27, 2001).]
[This message has been edited by Jim Yingst (edited March 31, 2001).]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ian,
I agree with ego on the first two.
Regards,
Manfred.
[This message has been edited by Jim Yingst (edited March 31, 2001).]
 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
f) int []q = {1,2,3}
Doesnt that need a ";"? It wont compile otherwise. So F cannot be a right answer.
 
Ian Heff
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right, Andy. I forgot to add the semicolon on the last one. Good catch!!
Ian
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
pls correct me if i am wrong.
First Question:
Select valid arrays declarations or initializations (Select 3)
a) int a[] = new int[5]; // valid
b) Double d = new double[4]; // invalid, nonsense
c) Char []c = "Element"; // nonsense
d) Object obj = new double [8]; // valid since arrays are objects
e) int ab[][] = {0,1,2} {1,5,6};//RHS should be{{0,1,2} {1,5,6}}
f) int []q = {1,2,3};//valid

Second Question:
I agree with Hu

[This message has been edited by Jim Yingst (edited March 31, 2001).]
 
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,
About question 2, isnt Object a valid answer ? A throw statement
can throw Exception, Throwable etc which are all derived from the
superclass Object. Given the way the question is framed,
why is Object not a valid answer ?
As for Error, can anyone give an example of how Errors are
explicitly thrown ? I thought that Errors are typically
not handled in exception handling.
Thanks
Sajida
 
Ian Heff
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill, I got a small mock test (~10 ?'s) from a friend of mine. He is working on creating an entire mock exam so maybe if he finishes and feels it is satisfactory he will post in on the web...
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ian,
What are the correct answers according to author please find out.
For Q1 a and f are obviously correct and for the third choice hoe can e be correct.Should'nt it be like {{0,1,2}{4,5,6}}.
For Q on throw statement is runtime exception correct option.
regards,
Madhuri.

[This message has been edited by Jim Yingst (edited March 31, 2001).]
 
sajida kal
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,
I have a question about question 2 ie what can the throw statement throw.
According to the javadoc API
quote..
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.
A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.
unquote
Looking at this, it seems that 'Error' is not a valid choice,
Can someone please clarify this ?
Thanks !
Sajida
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ian,
I think There need some modification in ur question 1 on which will make three statment true,
a) int a[] = new int[5];// valid
b) Double d = new double[4]; // Not Valid
c) Char []c = "Element"; // Not Valid
d) Object obj = new double[8]; // Here space should not be present then it is valid
e) int ab[][] = {0,1,2} {1,5,6} // Not Valid
f) int []q = {1,2,3};// Semicolon will make it valid

2) What can the throw statement throw? (select 4)
a) Error
c) RunTimeException
e) Exception
f) Throwable

[This message has been edited by Jim Yingst (edited March 31, 2001).]
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I fully agree with sajida.
There is no doubt in it. Error can't be a correct answer.
I think for q. no:2
c) RunTimeException
d) Object
e) Exception
f) Throwable
r the correct answer.
T H A N K S.
<marquee> Ratul Banerjee </marquee>

[This message has been edited by Jim Yingst (edited March 31, 2001).]
 
sajida kal
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
Would like to request one of the ranch moderators to comment on
my last post on this topic. The question was regarding the
choice of Error for question 2.

Thank you
Sajida
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, everyone - the thrid question in the original post is too close to an actual exam question, so I've deleted it. I couldn't find a way to make everyone else's comments about the question make any sense without the actual text of the question, so I went ahead and deleted all other references to the question. Sorry for the incinvenience everyone, but we can't have real exam questions floating around here (though I realize it was unintentional).
For those of you who remember the question and are worried about it: it was a poorly-worded question with no good answer. I believe that the mock exam "author" changed the question just enough to ruin its logic, so that it was impossible to answer correctly. It doesn't matter what the "author" though the answers were; he's wrong. Don't worry about it. When you take the real exam, read the questions carefully to se what they actually say; don't obsess over what someone misquoted.
Regarding the second question: an Error is not required to be declared in a throws clause. However it can be thrown. Those are two different sentences which mean different things - "throw" and "throws" are used in different places in a program. It is very easy to write some code which will throw an Error - try it. And try to write code that throws an Object. Not a subclass of an Object , but a plain Object. It's impossible. So the answers to question 2 should be obvious - just try writing some code to test your ideas if you have any doubts.

[This message has been edited by Jim Yingst (edited April 01, 2001).]
 
sajida kal
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 Jim,
Thanks for your clear response. I have understood the difference you have explained and will test it out
to reinforce it.
Regards
Sajida
 
Ian Heff
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Jim for posting a close question. I didn't realize that it was that close to an actual SCJP2 question. I guess the wording was why it was so confusing...
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic