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

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

Moderator: admin

Post Reply
stuie382
Posts: 1
Joined: Sat Jul 13, 2013 9:44 am
Contact:

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

Post 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. :(

Shortrope
Posts: 15
Joined: Sun Jun 01, 2014 8:27 pm
Contact:

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

Post 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.

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

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

Post 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 ?

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

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

Post by crazymind »

Ok, I see, it is narrow primitive conversion.

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

laura.lang
Posts: 3
Joined: Tue Jan 26, 2021 1:35 am
Contact:

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

Post 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)

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

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

Post by admin »

You are right. This video seems to be about something else. Removed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

enthunoob
Posts: 60
Joined: Thu Apr 15, 2021 12:21 pm
Contact:

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

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests