• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Little confuson.

 
Vijay Kumar
Ranch Hand
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I have little coufsion about interface and class.
I have to use some own defined Constant in my project what should be the best approach.Should I make an interface or a class which will have the dsired constant varaibles.
so please tell me whihc one is best in terms of memory,performace..


package com.test;
public class MyconstantClass {
static final int WXY=9;
static final int ABC=9;
}

or

package com.test;
public interface MyConstantInterface {
int ABC=1;
int xyz =3;
}


Thanks
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A field in an interface can only be static, public and final. Its implicit. I would suggest you go for a class.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and of course fields in interfaces are generally considered "not done" (Effective Java item 17).
 
Vijay Kumar
Ranch Hand
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jhon acc to you A field in an interface can only be static, public and final. Its implicit. I would suggest you go for a class. I agreed but whts the harm if I am using it..... & why would you sugeest for class.
my requirment is for public constant which can be use in any class. so I have define in interface.
please tell me some concrete soloution..
Thanks
 
scotta irwin
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you don't have any behavior or data to implement, developers typically would use an interface in these cases.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic