File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes QUIZ 002.Questions related to Core Java.? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "QUIZ 002.Questions related to Core Java.?" Watch "QUIZ 002.Questions related to Core Java.?" New topic
Author

QUIZ 002.Questions related to Core Java.?

Nitish Agrawal
Greenhorn

Joined: Feb 11, 2008
Posts: 21
Q9. int number[]=new int[5]; after execution which are true .?
A9.1.number[0] is undefined
2.number[5] is undefined
3.number[4] is null
4.number[2] is 0
5.number.length() is 5

Q10.String s=new String("abc"); which calls are valid.?
A10.s.trim()
s.replace('a','A')
s.substring(2)
s.toUppercase()
s.setCharAt(1,'A')
s.append("xyz")

Q11. given that a button can generate an action event which listener would you expect to hv to implement,in a class which would handle this event?
A11.1.FocusListener
2.ComponentListener
3.WindowListener
4.ActionLIstener
5.ItemListener

Q12. getIt()..? do what.?

Q13. Can we cast an integer to a float.?

Q14. in some statement it is given: j=2+m;
will it execut or giv sm error or what will happen.?

Q15.which code declares class A to belong to the
mypackage.financial package?
A15.1.import mypackage.*;
2.import mypackage.financial.*;
3.package mypackage.financial;
4.package mypackage.finamcial.A;
5."package mypackage; package financial;"
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Please look at the links Paul Sturrock gave you earlier.

We don't simply supply answers to questions like those. Please quote where you got the questions from, and also post what you think the correct answers are. Assuming you are not breaching copyright, we shall then be happy to look at your answers.
Nitish Agrawal
Greenhorn

Joined: Feb 11, 2008
Posts: 21
thanks for your suggestion too.
But dont take those answers as so easy.
Because accuracy in work shud always be there.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
In that case the correct answers are:
no 16: a, no 17: b and c, no 18: c and d, no 19: e, no 20: a and c.

The questions are quite easy; we want to see that you have answered them. I have told you so earlier, and so has Joanne Neal. Let's see some "accuracy in work" from you; it's your assignment.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3168
    
  10
Are you sure about 18 ? I would have said the answer was a and d.


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Not sure; actually I think maybe we were both mistaken first time and it's actually "a and c."
Lance Miller
Greenhorn

Joined: Jun 23, 2008
Posts: 21
The worst part is when the people who don't do their own homework graduate, get hired by your company, and then assigned to your team. It's always a lot of fun to "work" with them (and by that I mean carry them) for the 6 months before they finally get fired for not being able to actually program. That alone is motivation to not answer posts like this.
Nitish Agrawal
Greenhorn

Joined: Feb 11, 2008
Posts: 21
OK I agree.Sorry for all that i said you earlier. Actually i hv the answers now,but i want to know those answers in a very short amount of time,thats why i just posted them.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Apology accepted. Will you tell us your answers?
Shikhar Madhok
Ranch Hand

Joined: Dec 18, 2006
Posts: 95
Here is what I think the answers are

9) 2, 4, 5
(int will not be null so 1 and 3 are ruled out. int will by default be 0. array size is 5 to last element will be number[4]. hence 2 is true. 4 is true since default value of int is 0, and array length is indeed 5 since we initialized it so)

10) 1, 2, 3, 4
(all seem to be valid string calls. append is used with StringBuffer. Was not sure of setCharAt(). Checked API for String did not find the method)

11) Wild guess 4. (not good with this sutff)

12) I did not understand the question.

13) No. (at least I do not think so.) There is a hierachy of how you can cast between various datatypes. Have to look up on that.

14) if j and m are integer or float it should work fine. May acutally work for more datatypes as well.

15) 3.

I could be wrong in most answers. Just taking my shot at it.

Shikhar


He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever - Chinese proverb
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Originally posted by Shikhar Madhok:
Here is what I think the answers are

9) 2, 4, 5 2 and 4 are right, but 5 is wrong More details in the Java Tutorial; use ctrl-f to find "length".

10) 1, 2, 3, 4 1 2 right, 3 wrong (if you have copied it correctly) 4 wrong definitely. 3 might be a copying error. Go back to the String API and read the names of the methods very carefully.

11) Wild guess 4. Correct. The names of the classes are supposed to demonstrate what they do, so you can get your wild guesses right. It's actually an interface, not a class.

12) I did not understand the question. I think they mean you should describe what a "get" method does.

13) No. Wrong. It's rather complicated, but you will find it in the Java Language Specification; look for "widening primitive conversions."

14) if j and m are integer or float it should work fine. May acutally work for more datatypes as well. Correct. That should work for all sorts of numbers provided the result can be implicitly case to the type of "j".

15) 3. Correct
Now look up the references I have given, and learn what they say
Shikhar Madhok
Ranch Hand

Joined: Dec 18, 2006
Posts: 95
Q10) The options were
1)s.trim()
2)s.replace('a','A')
3)s.substring(2)
4)s.toUppercase()
5)s.setCharAt(1,'A')
6)s.append("xyz")

So I think 3 is correct. 4 is possibly a copy error. I think my answer 1, 2, 3, 4 (assuming 4 is a copy error) is correct.


Q13) The 'hierarchy' I was talking abt was

byte -> short
\
- > int -> long -> float -> double
/
char

Got it after I looked up the link.


What about the getIt() question? Would the answer be 'It returns the current value of variable' .. (for lack of any better words)
Thanks

Shikhar
Shikhar
[ July 24, 2008: Message edited by: Shikhar Madhok ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Originally posted by Shikhar Madhok:
Q10) The options were
1)s.trim()
2)s.replace('a','A')
3)s.substring(2)
4)s.toUppercase()
5)s.setCharAt(1,'A')
6)s.append("xyz")

So I think 3 is correct. 4 is possibly a copy error. I think my answer 1, 2, 3, 4 (assuming 4 is a copy error) is correct.
4 should read s.toUpperCase(); the C/c distinction is important. I think I have got this wrong; I thought there were only 5 possibilities. trim, replace and substring are real; toUpperCase is real, setCharAt and append are not real.


Q13) The 'hierarchy' I was talking abt was

byte -> short
\
- > int -> long -> float -> double
/
char

Got it after I looked up the link. That looks about right; you can implicitly or explicitly cast an integer to a float.


What about the getIt() question? Would the answer be 'It returns the current value of variable' .. (for lack of any better words)
Thanks Yes, that would be correct.

Shikhar
Well done Have you worked out what is wrong about no 9 yet?

And I am very sorry about getting the String methods question wrong.
Shikhar Madhok
Ranch Hand

Joined: Dec 18, 2006
Posts: 95
Had to try out sample code to find out what was wrong with 9.
It should read number.length instead of number.length()

Shikhar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Originally posted by Shikhar Madhok:
It should read number.length instead of number.length()
Correct.

Now what about the 1st quiz?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: QUIZ 002.Questions related to Core Java.?
 
Similar Threads
Marcus Green's mock up test questions
Can someone fix me?
java
Something i'm extremely confused on
Beginner Yahtzee Progam