About Question enthuware.ocajp.i.v7.2.1189 :
Moderator: admin
-
- Posts: 1
- Joined: Sat Jul 13, 2013 9:44 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1189 :
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.
-
- Posts: 15
- Joined: Sun Jun 01, 2014 8:27 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
I got this question correct but don't understand why opt 4 the description says
So you can instantiate an interface? But an interface is abstract.Since Runnable is an interface, it cannot be instantiated like this. But you can do :
Runnable r = new Runnable(){
public void run(){
}
};
-
- Site Admin
- Posts: 10061
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
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.
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.
-
- Posts: 85
- Joined: Mon Dec 24, 2018 6:24 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
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 ?
-
- Posts: 85
- Joined: Mon Dec 24, 2018 6:24 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
Ok, I see, it is narrow primitive conversion.
-
- Site Admin
- Posts: 10061
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
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.
-
- Posts: 3
- Joined: Tue Jan 26, 2021 1:35 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
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)
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)
-
- Site Admin
- Posts: 10061
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
You are right. This video seems to be about something else. Removed.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 60
- Joined: Thu Apr 15, 2021 12:21 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1189 :
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
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
Who is online
Users browsing this forum: No registered users and 102 guests