• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Marcus Mock # 3 Help!!

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I took Marcus Mock #2 last week and got 79%, and I was thinking to do better slowly. But today I took Marcus Mock#3 and completely lost my confidence. I am listing some of the questions, where I have doubts:
First of all, in one of the questions, there wasn't any match with the answer listed. So the description says, if you see this kind of problem in the exam, leave the question blank. Is it true?
Questions:
Which of the following statements are true?
1) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
3) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain
4) The instanceof operator can be used to determine if one reference is of the same class as another reference thus
Answer given is 2) I don't agree. Any thoughts?

Which of the following statements are true?
1) An interface can only contain method and not variables
2) Java does not allow the creation of a reference to an interface with the new keyword.
3) A class may extend only one other class and implement only one interface
4) Interfaces are the Java approach to addressing its single inheritance model, but require implementing classes to create the functionality of the Interfaces.
My answer was 2) and 4). But the given answer is 4)
Which of the following statements are true?
1) All of the variables in an interface are implicitly static
2) All of the variables in an interface are implicitly final
3) All of the methods in an interface are implicitly abstract
4) A method in an interface can access class level variables

Given answer is 1),2),3). All the interface variables are implicitly final and static? Also, a method in a interface can't access class level variables in a class, which is implementing that interface?

Given a reference called t to to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute.
1) t.yield();
2) yield()
3) yield(100) //Or some other suitable amount in milliseconds
4) yield(t);
Given answer is 2). I thought 1) should be correct answer (I know, yield() is static method of Thread class, but still you can access it using reference, right? Correct me if I am wrong. Also the description says yield() is static method of Object class.)
Given the following code
class Base {}
class Agg extends Base{
public String getFields(){
String name = "Agg";
return name;
}
}
public class Avf{
public static void main(String argv[]){
Base a = new Agg();
}
}
What code placed after the comment //Here will result in calling the getFields method of Base resulting in the output of the string "Agg"?
1) System.out.println(a.getFields());
2) System.out.println(a.name);
3) System.out.println((Base) a.getFields());
4) System.out.println( ((Agg) a).getFields());
First of all, there is no //Here in above code. So I assume, it would be after Base a = new Agg(); and so my answer was 1). But given answer is 4).
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sunny,
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
Answer given is 2) I don't agree. Any thoughts?

The answer is true. Since primitive Wrapper classes are class the instanceof operator can be used the above fashion.

Which of the following statements are true?
1) All of the variables in an interface are implicitly static
2) All of the variables in an interface are implicitly final
3) All of the methods in an interface are implicitly abstract
4) A method in an interface can access class level variables
Given answer is 1),2),3). All the interface variables are implicitly final and static? Also, a method in a interface can't access class level variables in a class, which is implementing that interface?

JLS says this about the field declaration in the interfaces:
Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted, but strongly discouraged as a matter of style, to redundantly specify any or all of these modifiers for such fields.
Here is the reference http://java.sun.com/docs/books/jls/html/9.doc.html#78642

Hope this helps
Ajay

[This message has been edited by Ajay Kumar (edited May 11, 2000).]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sunny,
First of all, a small request. Please post the questions separately if they don't discuss the same concept. This way the people who are sifting through the old messages won't miss anything. Moreover, it will be a lot easier to answer them

Okay, here we go -
Question #1
1 - is wrong because instanceof works even with interfaces.
2 - is right( see Ajay's response above. )
3. - is wrong because instanceof interprets the hierarchy
4. - is wrong because arguments to instanceof is a reference and clastype, NOT
two references.

Question #2
My answer was 2) and 4). But the given answer is 4)
You know why 1) and 3) are are wrong, so I will concentrate on 2).
Read it clearly, it says creation of a reference to an interface. Do not extend the meaning of the question. It would be a right statement if it said instead, creation of a reference to an object implementing the interface. Agreed, the wording is misleading, but that's the way it is So 2) is a wrong answer.

Question #3
A method in an interface can access class level variables - is false because, where is the method body?? An interface has only the method stub. !!! Again, don't extend the meaning of the question, work with what have been given to you. Just that
Question #4
Given a reference called t to to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute. My argument is it clearly says it, so we are talking about the running thread t. However, since yield is a static method, no matter on what thread you call it, it affects the running thread. IMO yield() is also a right answer and t.yield() is not a wrong answer
Question #5
Remember this is not polymorphism. The Gotcha is Base{} does not have a getFields() method. You have already done the blunder of assigning the derived instance to a base reference. Now, whatever you do with that base reference, it will try to operate on the baseObject contained in the derived reference. Since there is nothing that derived inherits or extends from the base polymorphic behavior is not displayed. The only way to get a "pure" reference back to the derived is ( by first repenting for not storing the derived reference anywhere, and ) by doing the explicit cast. It is like remembering who you are, after an acute attack of amnesia, by looking at your picture id !!!

Hope this clarifies the things for you. I too got dismayed after taking Marcus #3. Questions are easy, but they are tricky and you must read them under a microscope.


Ajith
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am putting some of my opinions, please correct me if I am wrong.
First.
2)is true. That's what instanceof is for. the question just particularly mentioned it's for "primitive wrapper class". but no difference.
Socend.
Actually, I have the same doubtness as you do. we all know that "interface can not be instantiated". we must be missing something here, someone please clear it.
Third.
That's right, all the variables in interface are final and static. And those methods in interface, they don't have body at all, how can they access any variable from anywhere.
Forth.
I don't think we are able to access static method through reference. if we can, we will have not only one copy of static method along with references.
Fifth.
(My version of mock 3, which only have 39 questions, doesn't contain this question. But according to what you have put here, I agree with your answer, 1) should be the right one.) after I post my message, I see Ajith's reply. now I know why. Thank you.
Indy
[This message has been edited by Indy (edited May 11, 2000).]
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to ensure my questions test your knowledge of Java and not your ability to untangle tricky sentence construction.
From reading this thread I get the impression that it is agreed that my questions and answers if strictly read are correct but maybe a bit misleading.
Let me know if you think I should re-phrase or simply get rid of these questions for more straightforward ones. I consider my exam3 to be still under development, I only finished the 60th question a few days ago.
I have given it more questions along the lines of "Which of the following statements are true" as I personally find it very dull reading through large blocks of code in questions :-)
Marcus

 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for jumping in Marcus.
No, your questions are not misleading. I guess one has to understand the subtle differences in the wording. After some analysis, I have found most of the mistakes ( at least for me ) happen not by reading the question properly. I am not blaming anyone here, but perhaps one must make use of all the time given to us to read the question at least twice before answering.
As for test #3, I have two suggestions. One is to fix the casting question mentioned here, which needs the // comment in the code where the answer needs to be filled in. The other complaint is the yield question. Perhaps you should include t.yield() too as the right answer. Don't you agree??
Again, thanks so much for listening to our grievances
Highly obliged,
Ajith
[This message has been edited by Ajith Kallambella (edited May 11, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to everybody who replied. I appreciate your help. Ajay, thanks for the link of JLS for interface. That was very helpful. Ajith, excellent explanation. But still I have doubt in last question, may be in the evening I should compile it.
Marcus, thanks a lot for participating in the discussion. I am an ardent admirer of you and your work. The questions are little tricky, but at the same time, it motivates you to prepare for the better. After making these mistakes, we will be cautious to not make same mistakes again in the exam.
By the way, any explanation for the yield() and last question?
Thanks,
 
Marcus Green
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Marcus, thanks a lot for participating in the discussion. I am an ardent admirer of you and your work. The questions are little tricky, but at the same time, it motivates you to prepare for the better. After making these mistakes, we will be cautious to not make same mistakes again in the exam. "
Thanks for the kind words. Although in my exams I say that people should assume the real exams will be harder, I actually think my stuff is either about the same level of difficulty or a little harder. But I wan't people to prepare well and not be
dissapointed.
Ajith, which question do you mean when you mention casting?. I am going to look again at the yield issue and some of the other wordings based on this thread.
Thanks again for all the comments it helps me build the quality of the material and helps other people who browse it.
Marcus
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<pre>
Given a reference called t to to a class which extends Thread, which of the following will cause it to give up cycles
to allow another thread to execute.
1) t.yield();
2) yield()
3) yield(100) //Or some other suitable amount in milliseconds
4) yield(t);
Given answer is 2). I thought 1) should be correct answer (I know, yield() is static method of Thread class, but still
you can access it using reference, right? Correct me if I am wrong. Also the description says yield() is static method of
Object class.)
</pre>
Just how would you go about doing it ?
When yield() is invoked it is invoked on the thread executing
that particular piece of code. So it is
"runningthread".yield() .
If you have an instance of Thread t in your code and
you do t.yield() even then the yield() would be
"runningthread".yield() rather than t.yield()

Originally posted by Sunny:

By the way, any explanation for the yield() and last question?
Thanks,


 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcus,
It is question #57 in Mock exam 3.
Regards,
Ajith
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Given a reference called t to to a class which extends Thread, which of the following will cause it to give up cyclesto allow another thread to execute.1) t.yield();2) yield()3) yield(100) //Or some other suitable amount in milliseconds4) yield(t);Given answer is 2). I thought 1) should be correct answer (I know, yield() is static method of Thread class, but stillyou can access it using reference, right? Correct me if I am wrong. Also the description says yield() is static method ofObject class.)


I am resurrecting the discussion...
Does yield()method guarantee that for sure, a new thread is going to get a chance. From what I read, i feel the yield() method may or may not give up thread of control to a different thread waiting in the runnable state?
Am I missing something?
Thanks in advance
Sri
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic