Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

about static methods calling....

This is a discussion on about static methods calling.... within the Java forums, part of the Software Development category; I have a static mehtod in my class. Which is the best way to call the static mehtod using Class or object instance of the class. I assume that compiler ...

Go Back   Geeks Talk > Software Development > Java
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Java Java related Issues and Problems

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,016
Thanks: 0
Thanked 91 Times in 72 Posts
psuresh1982 will become famous soon enough
about static methods calling....

I have a static mehtod in my class. Which is the best way to call the static mehtod using Class or object instance of the class.

I assume that compiler would resolve the call to the static method if through the Class at compile time and through object instance only at runtime.

Is compiler is intelligent enough to resolve the call through Object instance at compile time ?

Please explain this one...

-------------------
suresh
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-11-2007
Expert Member
 
Join Date: Sep 2006
Location: Bengalooru (Formerly called Bangalore), India
Posts: 486
Thanks: 2
Thanked 29 Times in 28 Posts
kalayama is on a distinguished road
Re: about static methods calling....

I think you do not have clear unserstanding of Static methods. For statius methods memory is created at compile time anbyway and everytime a new object is created (using new command), the JVM doesn't allocate memory to the static member function again. IN other words, there will only be one Memory location where static object will be present. And all the objects wil just refer it.

Unlkie the normal method where in a there will be a function associated with every object that is created.


So, there is no point in calling a static method through object. I can not imagine why one would want to do it and I have never seen anyone do it either. (Neither in C++ nor in Java).

Hope that clears things.

Cheers!
Kalayama
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Reply With Quote
  #3 (permalink)  
Old 05-11-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,016
Thanks: 0
Thanked 91 Times in 72 Posts
psuresh1982 will become famous soon enough
Re: about static methods calling....

So Kalayama you told Class is the best method for calling static methods. But i saw people calling the static method through object also.

Anyway thanks for your reply....

-------------------
suresh
Reply With Quote
  #4 (permalink)  
Old 05-11-2007
Expert Member
 
Join Date: Sep 2006
Location: Bengalooru (Formerly called Bangalore), India
Posts: 486
Thanks: 2
Thanked 29 Times in 28 Posts
kalayama is on a distinguished road
Re: about static methods calling....

Yes. It is possible to call static method though objects. But it serves no purpose unless you modify some varibles that are owned by that object. But, if you do that, it will be poor design because you don't need a static function to do object level jobs. A simple function would be enough.

So, in general static functions are called through Class. And I am certain it is better programming practice. One can easily identify that the method is static even wthout checking the clas declaration.

Cheers!
Kalayama
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Reply With Quote
Reply

  Geeks Talk > Software Development > Java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Dynamic and Static lookup JobHelper Data Warehousing 3 02-08-2008 10:38 PM
Static variables in multiuser environment Lokesh M C and C++ 3 12-26-2007 12:25 AM
Abstract, final and static keywords Geek_Guest Java 2 12-25-2007 09:48 AM
Public static final variables in interfaces ani_lavanya Java 1 05-02-2007 05:38 AM
Adobe Systems calling for tests for Quality profiles manishsinha Companies 2 02-08-2007 01:02 AM


All times are GMT -4. The time now is 02:28 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved