About Question enthuware.ocpjp.v7.2.1308 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Wisevolk
Posts: 33
Joined: Thu Jul 18, 2013 6:06 pm
Contact:

About Question enthuware.ocpjp.v7.2.1308 :

Post by Wisevolk »

Hi,
class MidiPlayer implements MusicPlayer<Instrument> {     public void play(Guitar g){ } }
Your answer : MidiPlayer must have a method play(Object ).

Is it right ? Shouldn't Midi player have a a method play(Instruments) ?

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1308 :

Post by admin »

Yes, it is correct because the method is actually coming from interface Player<E>{ void play(E e); }

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

lunars
Posts: 3
Joined: Sat Jun 28, 2014 8:43 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1308 :

Post by lunars »

This is my current understanding of the problem, further dissecting the uncertainty brought up by Wisevolk (see comments):

Code: Select all

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{ } 
/** 
 *  (1) When MusicPlayer extends the *RAW* "Player" above, that makes 
 *       "void play(E e);" effectively convert into "void play(Object o);"
 *  (2) So anything implementing MusicPlayer (regardless of generics used) 
 *       gets handed a version of Player's method(s) where E (only the E 
 *       inside Player) has been downgraded to Object (due to being raw)
 */

class MidiPlayer implements MusicPlayer<Instrument> {
	
	public void play(Instrument i){ }  // <-- 
	public void play(Guitar g){ }      // <-- neither of these can reference the raw version of Player 
	
	public void play(Object e) {}      // <-- comes from raw version of Player
	
}
Is that accurate?

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1308 :

Post by admin »

That is correct, lunars.
-Paul.
If you like our products and services, please help us by posting your review here.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1308 :

Post by jagoneye »

lunars wrote:This is my current understanding of the problem, further dissecting the uncertainty brought up by Wisevolk (see comments):

Code: Select all

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{ } 
/** 
 *  (1) When MusicPlayer extends the *RAW* "Player" above, that makes 
 *       "void play(E e);" effectively convert into "void play(Object o);"
 *  (2) So anything implementing MusicPlayer (regardless of generics used) 
 *       gets handed a version of Player's method(s) where E (only the E 
 *       inside Player) has been downgraded to Object (due to being raw)
 */

class MidiPlayer implements MusicPlayer<Instrument> {
	
	public void play(Instrument i){ }  // <-- 
	public void play(Guitar g){ }      // <-- neither of these can reference the raw version of Player 
	
	public void play(Object e) {}      // <-- comes from raw version of Player
	
}
Is that accurate?
Did not understand this and also why
MidiPlayer must have a method play(Object ).
Why can't I use type Instrument here?

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1308 :

Post by admin »

Try compiling using Instrument and see what the compiler error message says. That should help.
If you like our products and services, please help us by posting your review here.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1308 :

Post by jagoneye »

Actually I was trying to verify if this would work

Code: Select all

class MidiPlayer implements MusicPlayer<Instrument>
{
    public void play(Instrument o){ } 
}
And I didn't see that MusicPlayer was extending RAW Player!!! :(
What I thought was

Code: Select all

interface MusicPlayer<E extends Instrument> extends Player<E>{ }
and if this was the interface then my MidiPlayer will happily compile!

Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests