About Question enthuware.ocajp.i.v8.2.2012 :

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

Moderator: admin

Post Reply
nagarjuna19
Posts: 5
Joined: Sat Mar 17, 2018 6:21 pm
Contact:

About Question enthuware.ocajp.i.v8.2.2012 :

Post by nagarjuna19 »

Hi All,

Can anyone explain, why java interface is of Type and class has state.

"Java supports multiple type inheritance but not multiple state inheritance."

Thanks,
Nagarjuna

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

Re: About Question enthuware.ocajp.i.v8.2.2012 :

Post by admin »

interface, class, and enum are all type of types. When you define any of these, you are actually defining a type. Class has instance fields, which means, only class can define state.
Since a class can implement multiple interfaces, that means the class in inheriting multiple types. Since a class can extend from only 1 class, Java cannot inherit multiple states.
If you like our products and services, please help us by posting your review here.

nagarjuna19
Posts: 5
Joined: Sat Mar 17, 2018 6:21 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.2012 :

Post by nagarjuna19 »

Thank you

TamasBuri
Posts: 6
Joined: Thu Sep 26, 2019 3:19 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.2012 :

Post by TamasBuri »

Hi,

I am a little bit confused. You wrote :
"This is an important concept and is explained in more detail here: https://docs.oracle.com/javase/tutorial ... tance.html"
I readed that topic but I don't understand. It says:
"One significant difference between classes and interfaces is that classes can have fields whereas interfaces cannot."

But I know interface has fields. They are implicitly public static final fields.

In JLS 8 chapter 9.3 (Field (Constant) Declarations) page 285 says the same:
"Every field declaration in the body of an interface is implicitly public, static,
and final. "

Which one is true?

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

Re: About Question enthuware.ocajp.i.v8.2.2012 :

Post by admin »

JLS is more precise.
But the oracle tutorial is not wrong either because from the context of that tutorial, it is clear that the Oracle tutorial is talking about "state of an object" i.e. instance fields, which only classes can have.
If you like our products and services, please help us by posting your review here.

TamasBuri
Posts: 6
Joined: Thu Sep 26, 2019 3:19 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.2012 :

Post by TamasBuri »

Thank you

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests