Message Board


Message Board > Java > real primitive?

May 15, 2007, 15:06
DTM
Earthling!
823 posts

This is from an example exam paper:
Quote:
Which of the following methods would be regarded as "real" primitives in the Queue class (ie could not be implemented in any other way)?

a) public void addItem(Object theItem)
throws QueueExceptionOverflow

b) Object removeItem()
throws QueueExceptionUnderflow

c) public int getLength()

d) public Object clone()

e) public Object frontOf()
throws QueueExceptionEmpty

f) public boolean equals(Object other)



1 ) c, d, e and f.
2 ) a and b.
3 ) a, b, d and f.
4 ) a, b, c, and e.
5 ) All of the above.


What does it mean? I thought a primitive was just like an int,byte,double... etc

I didn't know methods could be primitive :/
____________
:o
#
May 15, 2007, 16:11
Dennis
どこかにいる
2097 posts

Maybe they mean you cannot override/overload some of these methods?

[Edited on May 15, 2007 by Dennis]
____________
Kwakkel
#
May 15, 2007, 18:04
DTM
Earthling!
823 posts

The correct answer was
2 ) a and b.

:S
____________
:o
#
May 15, 2007, 21:19
Frimkron
Frustrated Megalomaniac
703 posts

Its a bit of a stupid way of asking the question but I think they're getting at the fact that a queue by definition has a specific meaning associated with adding and removing items i.e. you add to the back and remove from the front (As oppose to a stack where you add to the front and remove from the front also). Whereas the other methods have no special meaning associated with the concept of a queue.
____________
#
May 16, 2007, 11:24
Dennis
どこかにいる
2097 posts

Now that I know the answer I might give an explanation. "cannot be implemented in another way". Maybe they mean you cannot create your own methods doing the same as those. ie.

a) Can you write your own method to add an item to a queue without using the method addItem() ? No
b) ... removeItem()? No
c) ... getLength() ? Yes, you can get the length of a queue with this, but you can do this in other classes too, it is not primitive, you can write your own method as we speak: object length in bytes? dunno...
d) ... clone() ? same anwser
e) ... frontOf() ? same answer
f) ... equals() ? same answer (isInstanceOf?)

Anyway, that would be my explanation.
____________
Kwakkel
#
May 16, 2007, 14:20
Moogle
Enterprise Edition
239 posts

Frimkron seems to be right on the money again :-)
____________
I am Moogle and I approve this message.

Quoting (. )( .) in the Bugs topic:
Everytime I login the threads with new posts are by Dennis.
#
May 16, 2007, 14:28
Dennis
どこかにいる
2097 posts

Quoting Moogle:
Frimkron seems to be right on the money again :-)
why not e) then?
____________
Kwakkel
#
May 17, 2007, 23:04
Frimkron
Frustrated Megalomaniac
703 posts

Quote:
why not e) then?


Hmm good question.

I can only guess that its because "front" could be ambiguous maybe? I mean you could call the front the front or the front the back or the front the top...
____________
#
May 17, 2007, 23:08
Dennis
どこかにいる
2097 posts

maybe you just have to learn this by heart... How else can you possibly know what the primitive methods in a Queue class are (and why would one care?).
____________
Kwakkel
#
August 5, 2011, 17:35
Zomg
None
641 posts
You can encapsulate/box/overload a primitive and an operator.
____________
#
August 15, 2011, 23:59
Dennis
どこかにいる
2097 posts

and since a and b are the only ones that are encapsulated methods here? Since the rest is "public" ? iono. 4 years have passed since my last post and my knowledge around this has only dropped since. :p
____________
Kwakkel
#
August 19, 2011, 21:20
DTM
Earthling!
823 posts

I still don't understand but luckily I don't need to any more.
____________
:o
#
August 23, 2011, 11:00
Dennis
どこかにいる
2097 posts

no one ever did need Java.
____________
Kwakkel
#

Message Board > Java > real primitive?

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!