Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface

 
Subhendu Dash
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do all methods in an Interface has by default Public visiblity mode..???
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Subendhu, and welcome to the Ranch!

Your question is answered here.
 
Subhendu Dash
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why default access visiblity can't be used with interface methods.say for ex-if i have an interface and i want only the classes in the same package to implement and thus use it.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i have an interface and i want only the classes in the same package to implement and thus use it.

That's answered in the next sentence after the answer to your original question.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface represents the public face of the class which implements it. That is why all members have the same access.
 
Subhendu Dash
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if we want abstract methods that can be implemented only on the same package then we can use an abstratc class(by making the methods abstract and default ) rather than an interface..Isn't it???
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic