Question from mock exam for SCJP 5

Hi everyone,
I have encountered this question:
class Game{ }
class Cricket extends Game{ }
class Instrument{ }
class Guitar extends Instrument{ }
interface Player<E>{ void play(E e); }
interface GamePlayer<E extends Game> extends Player<E>{ }
interface MusicPlayer<E extends Instrument> extends Player{ }Identify valid declarations.
And one of the possible answers is (which is not correct):
class MidiPlayer implements MysicPlayer {
   public void play(Guitar) {}
}And the explanation given why it is a wrong answer is:
"Observe that this is a non-typed usage of MusicPlayer. Since MusicPlayer has not been typed to
anything, that means, it should be able to work with any object. Thus, MidiPlayer must have a
method play(Object )."
But this explanation in my opinion is wrong as play(Object) would not satisfy MusicPlayer
interface. It would have to be play(Instrument) ... Am I right here ?
Cheers,
Adrian

But this explanation in my opinion is wrong as play(Object) would not satisfy MusicPlayer
interface. It would have to be play(Instrument) ... Am I right here ?
Cheers,
AdrianYes, and no.
play(Object) WOULD satisfy the MusicPlayer interface, because Object is the super class of Instrument. The requirement for a class to implement an interface is that its parameter types be able to accept the types specified in the interface, and its return type be a type or subtype of the return type from the interface.
So technially, it should be instrument, BUT
It is perfectly valid to accept any super type of Instrument, which includes java.lang.Object. The point is that if I do this:
MusicPlayer musicPlayer = new MidiPlayer();
musicPlayer.play(new Guitar());This MUST be legal. Since MidiPlayer has a play operation that is void and accepts an Object (which a Guitar happens to be a subtype of), this is legal. The restriction is that the play method cannot take type Guitar, because not all Instruments are Guitars, and the play method cannot take String, for example, because an Instrument is not a String. But it can define a parameter of type Object, because all Instruments are Objects.
I'm not sure if that made much sense, but that's the answer you're looking for. Here's the relevent section from the JLS:
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#38649
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.8.3
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.8.4
- Adam

Similar Messages

  • Mock exams for 1Z0-047

    Does anyone know of any official mock exams for the SQL Expert exam (1Z0-047)? All I can find are dodgy brain dump sites...
    Also how realistic are the questions in the Master Exams that come with OCA Oracle Database SQL Certified Expert Exam Guide (Exam 1Z0-047) (Osborne Oracle Press Series) - Steve O'Hearn? The questions at the end of each chapter seem far too simple to me and are much easier than the 7 or so sample questions on the Oracle page for this exam. Any thoughts from those who have taken the exam and used this book?
    Willy

    WillyM wrote:
    Does anyone know of any official mock exams for the SQL Expert exam (1Z0-047)? All I can find are dodgy brain dump sites...
    Wll Kaplan the official Oracle Partner appears to be offering them here ....
    http://certification.oracle.com - Preparation - Practice Tests .....
    http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=208
    Also how realistic are the questions in the Master Exams that come with OCA Oracle Database SQL Certified Expert Exam Guide (Exam 1Z0-047) (Osborne Oracle Press Series) - Steve O'Hearn? The questions at the end of each chapter seem far too simple to me and are much easier than the 7 or so sample questions on the Oracle page for this exam. Any thoughts from those who have taken the exam and used this book?What follows if thru memory
    ( The questions the the end of the first few chapters are trivial ... they then become more relevant ).
    Well I found the book helpful and from what I can remember the practice tests helped point some gaps I had.
    Typically I think I find real exams sometimes need a bit longer than that on some of the practice tests.
    I personally only use practice tests when i think i have learnt all material as a check to where i'm at and to identify gaps.
    I will even leave the end of chapter tests under i think i have grasped everything.
    And I will never take end of chapter tests if i have read that chapter earlier in the day!
    ( If i get tempted must take end of chapter tests early then i choose a reasonably meaty chapter about 1/3 into the book).
    The book was enough for me .... but it may not be so for everyone ... we can be different and start from different places.
    Someone mentioned they got rhu the test easily in an hour .... well i was pushing time the whole way through!
    >
    WillyRgds

  • Mock exams for Oracle EJB cerficication (CX-310-093)?

    Hello,
    Can you please help me by posting existing commercial or free mock exams for CX-310-093?
    The full name of the certification is: Oracle Certified Expert, Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer
    Thanks

    875304 wrote:http://www.epractizelabs.com/certification/sun/oce-ejb-exam-6.html
    You can try Java EE 6 EJB OCE Certification Training Lab.
    Please when suggesting material give some indication of the material's providence and your providence
    (ie are you a spammer or forum points seeker).
    As it happens certguard.com regards www.epractizelabs.com as certifcation safe (at least when last verified 2008) at time of post.
    This post looks like spam ... however your other two current posts indicate you appear to be something other than a spammer ... just and only just.

  • Question from Sun ePractice exam for SCJP

    Hi All. I�m preparing to take the SCJP for Java 5 test shortly, and in preparation I am taking one of the Sun ePractice exams for this test. I have run across an answer I don�t understand and am hoping that someone might help me better understand their explanation. I have included the question and answer below.
    Here's where I'm fuzzy: I selected option A, compilation fails, as the answer. As you can see by their answer, option A is, in fact, the correct answer. However, I thought the compilation error would be due to the statement on line 10. The statement on line 10 is attempting to assign a superclass object of type Dog, referenced by d2, to a reference variable for a subclass of Dog, h1 of type Harrier, without an explicit cast. But their answer states that the compilation will fail due to an error on line 8, not line 10. I don�t understand this. With respect to line 8, I can see that a cast from a subclass to it�s superclass would make the code more clear, but I don�t see why the compilation would fail due to no cast on this line. Furthermore, the compilation will certainly fail from the statement on line 10. I ran the code, and it did fail due to line 10. Do you think this is just a mistake in their answer, or am I missing something?
    Any insight would be much appreciated.
    The question and answer from the practice exam are as follows:
    Given:
    1. class Dog { }
    2. class Harrier extends Dog { }
    3.
    4. class DogTest {
    5. public static void main(String [] args) {
    6. Dog d1 = new Dog();
    7. Harrier h1 = new Harrier();
    8. Dog d2 = h1;
    9. Harrier h2 = (Harrier) d2;
    10. Harrier h3 = d2;
    11. }
    12. }
    Which is true?
    A-     Compilation fails
    B-     Two Dog objects are created
    C-     Two Harrier objects are created.
    D-     Three Harrier objects are created
    E-     An exception is thrown at runtime
    Answer:
    Option A is correct. The compiler will issue an incompatible types error because of the assignment on line 8.

    Did you buy these practice exams off sun. I remember this question. It confused the hell out of me too. Yes you are correct it fails because of line 10.

  • New Version of Mock Exam

    The new version of my mock exam for the Java Programmer Certification is available at the URL that appears at the end of this post. The new version has a set of two Basic Exams and also a set of 144 questions distributed across ten topic specific exams and alternatively organized as a set of eight comprehensive exams.
    This new version has 43 new questions relative to the old version. Most of the new questions are concentrated in three new topics: Constructors, Strings, and StringBuffers. The three new topics can be found on the Topic Exam page or you can find all 43 questions organized as a set of two exams on the New Questions page.
    My exams are very difficult. First time visitors are encouraged to start with the set of two Basic Exams. Try the Topic Exams next and use them as you work through your study guide chapter-by-chapter. For example, if you complete a chapter that covers inheritance, then try the Inheritance exam. The Comprehensive Exams should be saved for last. Those that have already completed my exams should try the New Questions page.
    The answer pages contain explanations for the answers and links to reference materials such as the Java Language Specification and a link back to this message board.
    My home page contains a set of exams organized by date. Always use the latest version since the older versions may be deleted without notice.
    http://www.geocities.com/danchisholm2000/

    I have a question for those on this message board that are certified java programmers. Do you feel that studying for the exam was a valuable learning experience? Can you give an example of something interesting that you learned while studying for your certification?

  • Confusing SCJP 6 mock exam questions

    Given:
    *class StringSplit {*
    *public static void main(String [] args) {*
    String s = "x1234 y56 z7 a";
    String [] sa = s.split("\d");
    int count = 0;
    for( String x : sa)
    count++;
    System.out.println("total: " + count);
    What is the result?
    The "correct" answer for this question on the guide I'm using is 8.
    I chose "Compilation Fails" based on my prior experience with other mock exams because some questions like these say that \d needs an extra \ (so \\d). For crying out loud, I even tested this code and it failed due to the missing escape.
    Anyway, when I run into this type of question on the SCJP, and there's something like \d or \w or \s showing up, should I assume that it's a valid delimiter or assume that it's not escaped properly?
    Thank you.
    Edited by: lapchern on Feb 1, 2010 10:31 PM
    Edited by: lapchern on Feb 1, 2010 10:34 PM

    please, edit your question and use the tag (there is a button in the editor window)                                                                                                                                                                                   

  • Mock exams & tips wanted for programmers exam

    Hi there, I am taking the 'Sun Microsystem's' exam in 'Java Programming',in just over 4 weeks. I wondered apart from taking a clean pair of underpants to the exam, or selling my soul to the devil, if some of you have any constructive advice.
    First of all I would appreciate any addresses of websites that may have mock papers of the actual exam.
    Secondly is there anything else you would strongly recommend I should do in preparation.
    I would be extremely grateful for your help, thanks, Dave.
    [email protected]

    Check out http://www.javaranch.com/certfaq.jsp
    Other than that, get a good certification prep book and work through it. My favorite is A Programmers Guide to Java Certification - http://www.amazon.com/exec/obidos/ASIN/0201596148/ , but there are several good ones. You'll probably need to try a few things out by writing simple code. Mock exams, including those in the books, are great preparation, although you'll find that some of them are lower quality than others. One piece of advice - don't pay for mock exams - it's just not necessary.
    Good Luck

  • HT201272 I have recently picked up an Apple TV. When I go to the movies tab, there are less movies available there than there are in my i-Tunes account. I've done some looking around at questions from others, but haven't found an answer that works for me.

    I have recently picked up an Apple TV. When I go to the movies tab, there less movies available there than what is available in my i-Tunes library. I have 38 movies showing in my library but only 23 are showing in the Movies tab on the Apple TV. After researching this a little, there are only 23 movies showing under Purchased in the Quicklinks of my i-Tunes account. The majority of my collection are digital copy downloads that came from DVD purchases. Some of the missing movies were added in the past couple of months, the rest are a year-or-so old. I have done some looking around at questions from others, but I have not found an answer that will fix my situation. How do I update my library to get ALL of my movies to reflect that they were "Purchased"(as it says they were in their Properties)?

    Biggles Lamb wrote:
    Chill out guys, getting personal will never ever change another persons view, right or wrong, they are entitled to them .
    The pros and cons of to CC or not to CC have been done to death
    Its a fact the CC model will work for some, especially newbies and small businesses.
    The risks associated with the CC model have been well documented.
    For long term users of CS perpetuals its generally a large hike up in cost compared to the upgrade system.
    Then there are the....... Adobe can rot it hell...... group who will never subscribe
    To each their own, you do the math to suit your cashflow whatever that is and then make an informed decision
    To those on the CC model, I'd like to offer some practical advice.........do not allow automatic updates.........make regular backups............develop an exit strategy of alternatives for when you can no longer afford the subscription costs............never ever assume that the Adobe update is bug free
    Enjoy your cloud
    Col
    Thank you for that post, and the advice. I just happen to be one of those who it does work for. I've been around long enough to know that CC isn't going to work for everyone(the large publishing/radio/web company I work for isn't upgrading to CC because of the costs involved). But it does for me as I potentially venture out into the full-time freelancing world and away from the more structured big office environment. I can't make decisions based on what is best for anyone else, or what will hurt or help Adobe. Just what affects me, and that's all.
    Brent

  • .jar file for java mock exams

    Dear all,
    please tell me where can i find the .jar file of java mock exams?
    Thanking you,
    Mitesh.

    I don't know about a .jar file, but here is a link for some
    quizzes: http://developer.java.sun.com/developer/Quizzes/
    Mark

  • HT5312 Hello I have purchased the account from the shop for mobile phones and when Dgt a balance of $ 75 U.S. dollars tried to go down some programs, but ask me to answer questions and there have even when the shop is not accepted to give me any data abou

    Hello I have purchased the account from the shop for mobile phones and when Dgt a balance of $ 75 U.S. dollars tried to go down some programs, but ask me to answer questions and there have even when the shop is not accepted to give me any data about amyl which bearing correctly and password also trueThe name is true, how can I re-answer these questions??? replace phones is that Ahab Please give me the quick fix and sent the answer to Emile is:[email protected]

    Well I can't understand your english at all. If you need to reset your security questions, then try this:
     Account Security Team (AST) 
    Check the AppleCare number for your country here:
    http://support.apple.com/kb/HE131
    Call them up, and let them know you would like to be transferred to the Account Security Team.
    Or… click on the blue "Start your support request online" links.

  • Test question from firefox nightly mac for finitarry

    text of test question from firefox nightly mac for finitarry

    the link is actually
    http://wiki.apache.org/spamassassin/SpamAssassinon_Mac_OS_XServer
    what you have posted takes one to a "page does not exist yet" error page

  • Online resource for SCJP

    Hi All
    Is there any online resource from where I get the material for SCJP or
    kind of online exam I can go thru for practice
    plz let me know
    Thanks
    Niraj

    Hi,
    You may also wish to take a look at : http://www.javacertificate.com/
    I found this site very useful when I was studying for the SCJP exam. It has practice questions which are also split into subjects allowing you to study a single area at a time. It also contains mock exams.
    Hope this helps.
    Ben.

  • Syllabus for SCJP 6.0

    Hello there,
    I am preparing for SCJP 6.0 and using the book SCJP1.6 by kathy seirra and bert bates. Can you please tell me if there is anything else that I will have to study to cover the syllabus for the exam..
    The reason why I am asking is that I am taking mock exams and few of the questions are based on some topics that are not in the book.....
    Can you please send me the information?
    Thanks!

    VShan wrote:
    While answering questions on the exam, will I know whehter I have answered correctly or not during the course of exam??No

  • Preparing for SCJP?

    Hi
    My name is Jon T and I am a programmer with a local company. I support and develop client�s applications. I use the following in daily process
    Unix (HP-UX)
    Oracle (Toad)
    VB
    ASP
    etc ..
    I have a basic foundation in Java and I am learning and preparing for Java Certificates.
    Has anybody passed the test successfully who started from the beginning level?
    Say, if I started today, is it possible to pass the test by May/June?

    I agree if you are programmer and study an hour or 2(include reading and doing programming practice).
    You need to read the book for SCJP. It is better if you can use the quiz and got a score close
    to 90%.People recommend the test from whizlab and you have to pay fee.
    The questions in the quiz is close to the exam in SCJP and it may help you familiar with the concept.
    The book written by Kathy Sierra is good.
    There are some free quizs on the internet. I myself have not bought the quiz from whizlab. I succeeded in SCJP 1.4 after one retry.

  • What is the best practice exam for 70-462 SQL 2012 DB Admin. exam?

    Hi All,
    I've completed the 70-462 exam prep guide from Microsoft press, i.e., I've read the book twice and practiced everything I could on my lab network (short of AlwaysOn and Clustering), including all the review questions and practice sections.  Now I need
    a practice exam and I'm wondering what success test-takers would suggest.
    I saw Transcender's practice exam for 70-461 and it was less than what I expected.  There were questions that didn't belong there and I don't want to waste my money on a practice exam that has a bunch of "filler" questions.  It was the
    first Transcender practice exam I've ever seen.
    Thanks for any advice you can provide!  I expect to take the exam in about 3 weeks.
    Eric B.

    Seriously, though, I've been studying this guide for nearly 6 months, don't have the money to re-test over and over, and would rather pay for a practice test than pay for the exam itself more than once.
    Hi Eric,
    In addition to Kalman’s post, based on my research, you can take a practice test for 70-462 from below link. Also, as is suggested in this
    article, you can buy a practice test for Exam 70-462 from Kaplan SelfTest and MeasureUp.
    http://www.accelerated-ideas.com/free-70462-practice-test.aspx#.VGRCzf6KCM8
    Besides, about such issues, for quick and accurate response, I would like to recommend that you ask the question in the Learning forums at
    https://social.technet.microsoft.com/Forums/en-US/home?forum=CertGeneral  . It is appropriate and more experts will assist you.
    Thanks,
    Lydia Zhang

Maybe you are looking for

  • IPhone 5s will not show in Itunes 11.3 after update

    Hi Folks, Updated iTunes to 11.3.0.54 and restarted my machine (running win 8.1).  Now when I dock the IPhone (5s running 7.1.2) it shows the 'Trust' prompt and when accepted, sounds a tone, then does nothing.  ITunes does not show any phone connecte

  • I'm really frustraded - Please help - Trouble with printing

    Hello guys, Im programing a software for a parking lot in java. I need to print tickets with an EPSON U220 printer. When I print, the margins of the paper are all messed up. It seems I can only print from the half of the paper to the left. What can i

  • How do I disable a Mac Safari Extension?

    Everytime I look at anything, including my OWN website of items for sale, I can't see the copy under the photo because the darn box of comparable items (which are NOT so comparable) hides all of my text and prices. I have tried everything and can't f

  • How to access filled in values of an af:query component

    Hi, I have a viewobject with a viewcriteria defined on it. The results are showed in a result table. When a user selects a row from the result table a new page is showed with detail data. In that page i would like to show the user the filled in attri

  • How do you program sprites in JAVA ?

    As far as I understand, a sprite is something you can move about without disturbing the background, because it is not paert of the frame buffer. But how do I write a code for it? Could someone please give me some hints?