• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Instance declaration

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between the following

1). public final int va=9; --- Constant Variable

2). public static int va=9; --- Static Variable or Class Variable

3). public static final int va=9; --- ???
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is class variable and a constant. What exactly do you want to know?
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anayonkar Shivalkar wrote:It is class variable and a constant. What exactly do you want to know?



I want to know that

interface SuperInterface{
public static final int va=9;/*(1)*/
public final int kva=9;
public int g=10;
}

(1) is a constant class variable..as per your reply and i agree with you..but it is required to define/allow it in interface???
Because interface is not a Class...
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gaurangkumar Khalasi wrote:

Anayonkar Shivalkar wrote:It is class variable and a constant. What exactly do you want to know?



I want to know that

interface SuperInterface{
public static final int va=9;/*(1)*/
public final int kva=9;
public int g=10;
}

(1) is a constant class variable..as per your reply and i agree with you..but it is required to define/allow it in interface???
Because interface is not a Class...



the variables defined in an interface contract are implicitly public static final while methods defined are implicitly public and abstract. so that means if you are talking about interfaces then there is no difference between
public int a = 9;
public static int a = 9;
public static final int a = 9;
int a = 9;
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks gurpreet.

but why there is a need of Class Constant variable(e.g. public static final int a = 9; ) in Interface...

Because of interface contract.....
 
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gaurangkumar Khalasi wrote:What is the difference between the following

1). public final int va=9; --- Constant Variable



In above scenario final means you can't reinitialize it and va is a instance variable but we call it constant variable because of this behavior.

Gaurangkumar Khalasi wrote:2). public static int va=9; --- Static Variable or Class Variable


In above scenario static means va is a class variable and you can reinitialize it .

Gaurangkumar Khalasi wrote:3). public static final int va=9; --- ???


Then in above scenario static and final means ?? you can't reinitialize va becauseof final and becauseof static va is a class variable .

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gaurangkumar Khalasi wrote:Thanks gurpreet.

but why there is a need of Class Constant variable(e.g. public static final int a = 9; ) in Interface...

Because of interface contract.....



If you need some class constant variables in all classes those implementing your interface then it will be better idea to declare and define in interface rather than in each separate class.
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

saloni jhanwar wrote:

Gaurangkumar Khalasi wrote:Thanks gurpreet.

but why there is a need of Class Constant variable(e.g. public static final int a = 9; ) in Interface...

Because of interface contract.....



If you need some class constant variables in all classes those implementing your interface then it will be better idea to declare and define in interface rather than in each separate class.



Your answer gives some sense...and i think it is correct definitely...

Thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic