Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Sat Jul 13, 2013 9:47 am
by stuie382
Ok so I'm pretty sure the question asked me to select 3 answers, however during the review it shows that I needed 4 answers. :(

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Sat Jul 26, 2014 3:15 pm
by Shortrope
I got this question correct but don't understand why opt 4 the description says
Since Runnable is an interface, it cannot be instantiated like this. But you can do :
Runnable r = new Runnable(){
public void run(){
}                     
};
So you can instantiate an interface? But an interface is abstract.

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Sat Jul 26, 2014 8:25 pm
by admin
You are not really instantiating an interface here. You are instantiating an anonymous class that implements the interface.
Not required for the exam, but you may go through this if you would like to know more: http://docs.oracle.com/javase/tutorial/ ... asses.html

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Fri Jan 04, 2019 2:49 pm
by crazymind
Hi, why does char ch = 10; works without any casting? I understand it can fit in a char but you always need a cast when you assign a int to a char, right ?

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Fri Jan 04, 2019 3:19 pm
by crazymind
Ok, I see, it is narrow primitive conversion.

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Fri Jan 04, 2019 11:54 pm
by admin
More precisely "implicit narrowing" i.e. narrowing without any explicit cast. Explained on pg 69 section 3.3.3 of OCAJP 8 Fundamentals by Hanumant Deshmukh book.

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Sat May 29, 2021 7:04 pm
by laura.lang
In the Explanation, there is a nice new feature to short video explanations. However, this one is not the correct link.

You may want to check out the free video by Dr. Sean Kennedy explaining this question: https://youtu.be/flTBt8zfHtQ  

This link takes me to an explanation about question -
Java Tutorial on Anonymous Inner Class syntax (enthuware.ocajp.i.v8.2.1110)

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Sat May 29, 2021 11:33 pm
by admin
You are right. This video seems to be about something else. Removed.
thank you for your feedback!

Re: About Question enthuware.ocajp.i.v7.2.1189 :

Posted: Wed Jul 14, 2021 5:58 am
by enthunoob
char ch =10; works because even though it is an int, it is a compile time constant, thus the compiler can figure out it is safe.

Examples from the above references book (page 73):
char c3 = 1; //ok, even though 1 is an int but it is a compile time constant whose value can fit into a char.
char c4 = -1; //will not compile because -1 cannot fit into a char