• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface question....

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, Interface's can only 'extend' other interfaces, right?

I thought they could implement one to many interfaces, but I guess they can only extend one to many interfaces.

Just wanted to make sure.

I also have an ENUM question as well,

in the following code:



I don't see how it knows that 'DOG("woof")' calls the enum's constructor without using a 'new' operator?

Thanks,

Justin Fox
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Justin,

Yes, interfaces use the "extends" keywords, followed by a list of extended interfaces -- there can be one or more. Classes extend classes, classes implement interfaces, interfaces extend interfaces, interfaces implement nothing.

About the enum: the compiler doesn't really "know" so much as it "assumes"; at that point, it's expecting to see enum values, and if it sees an open-paren, then that's assumed to be a constructor call. It "assumes' rather than "knows" because that's the only choice, and if the syntax turns out to be wrong, then it's an error.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool deal,

Thanks for clearing that up for me.

I'm studying for the scjp so be prepared for mucho posts .

Thanks again,

Justin Fox
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An enum is like a special kind of class. The enum constants are like public static final members of the class. Have a look at this:

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, once I figured out what it was 'assuming' i guess, I could kinda visualize a 'behind the scenes' declaration of the animals.

Thanks again,

Justin Fox
[ July 03, 2008: Message edited by: Justin Fox ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic