Answer A shall be right, too.
I have thought Runnable is an interface, so there is no way to call 'new' on it.
Is that different with inner classes ?
About Question enthuware.ocpjp.v7.2.1439 :
Moderator: admin
-
- Posts: 37
- Joined: Mon Jun 12, 2017 2:16 am
- Contact:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1439 :
Yes, option 1 is indeed a correct option. In this case, you are not instantiating Runnable interface but an anonymous class that implements Runnable interface. So the "new" is not really for Runnable, it is for that anonymous class.
If you like our products and services, please help us by posting your review here.
-
- Posts: 11
- Joined: Thu May 28, 2020 9:53 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1439 :
As the Thread t = new Thread(a) which means 'a' should be Runnable object so how Option C will be correct as it defines a thread object. Please explain.
-
- Posts: 11
- Joined: Thu May 28, 2020 9:53 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1439 :
Is it that thread class also implements runnable so it is allowed?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1439 :
Yes, Thread implements Runnable.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 32 guests