Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is static variable and static method?

Answer Posted / santosh

Ordinarily, when you create a class you are describing how
objects of that class look and
how they will behave. You don’t actually get anything until
you create an object of that
class with new, and at that point data storage is created
and methods become available.
But there are two situations in which this approach is not
sufficient. One is if you want to
have only one piece of storage for a particular piece of
data, regardless of how many objects
are created, or even if no objects are created. The other
is if you need a method that isn’t
associated with any particular object of this class. That
is, you need a method that you can
82 Thinking in Java www.BruceEckel.com
call even if no objects are created. You can achieve both
of these effects with the static
keyword. When you say something is static, it means that
data or method is not tied to any
particular object instance of that class. So even if you’ve
never created an object of that class
you can call a static method or access a piece of static
data. With ordinary, non-static data
and methods you must create an object and use that object
to access the data or method,
since non-static data and methods must know the particular
object they are working with.
Of course, since static methods don’t need any objects to
be created before they are used,
they cannot directly access non-static members or methods
by simply calling those other
members without referring to a named object (since non-
static members and methods must
be tied to a particular object).

Is This Answer Correct ?    24 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is bmg file and how to create that files?what will it contailn?

2296


what is inner class in java?

1074


What is use of valueof () in java?

999


What is comparator in java?

951


What is the difference between a field variable and a local variable?

1025


Can one thread block the other thread?

976


What are 4 pillers of object orinted programming?

944


What will happen if static modifier is removed from the signature of the main method?

909


What is meant by anonymous class?

974


What is pre increment and post increment in java?

942


What is the purpose of main function in java?

970


What is number data type?

969


How can we find the actual size of an object on the heap?

1262


What do u mean by variable?

991


When should the method invokelater() be used?

972