File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about global,local,class variable..!!!

 
sharma anurag
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi to all my friends of this is Forum,

please tell me about global,local and class variable,with thier respective examples.

Thanks in advance.
regards,
Anurag....!!!
 
Ganesh Kumar
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sharma,
Global variables are those which are not declared in the methods.Scope of these variables are inside that class only.

Local variables are those which are declared in the methods.Scope of these variables are only inside that methods.


(e.g)


class sharma{

int a;---------->Global Variables

void call(){

int b;----------->Local variables

}



I hope you got it !!!


Regards
GK
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A global variable is a variable available in every scope. Java doesn't really support global variables (though a public static variable is as close as you'll get).

class variables are variables defined once for the class, i.e. :

Because they are static they are associated with the class rather than a particular object instance (i.e. every instance of Foo shares the same bar variable).

A local variable is a variable available in a limited scope. It differs from an instance variable, which is available to an instance of an object, because it is further limited by the scope of a block of code. Examples:


Make sense?
[ August 30, 2007: Message edited by: Paul Sturrock ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic