answersLogoWhite

0


Best Answer

In Java, a static function is not attached to a particular object, but rather to the whole class.

For example, say we have the following class:

class Song {
String song;

void printSong() {
System.out.println(song);

}

static void printStaticSong() {
System.out.println("This is a static song. It has no tune.");

}


}

The static function Song.printStaticSong() can be accessed without creating an instance of the Song class (using the "new" keyword)

However it cannot access the members of Song (such as song), since it is not an instance of that object.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What do you mean by a static function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is function of static relay?

function of static relay


What is the function of static relay?

function of static relay


What is the difference between static function and global static function?

'global static'?! There is no such thing.


What do you mean by moving the static function declaration before the function body?

Before:static fun (void) {...}After:static fun (void); /* moved here */....static fun (void) {...}


What is the Use of static function?

A static function is a member function that is not associated with any instance of the class; it has no this pointer.


How do you create static variables in PHP?

Use the "static" keyword to declare a static variable within a function like shown below. <?php function fun() { static $variable; static $another_variable = ''; } ?>


Scope of static variables?

Scope of static variable is with in the file if it is static global. Scope of static variable is with in the function if variable is declared local to a function. But the life time is throughout the program


When Static function can work with static data member only?

Always.


Can static member function be overloaded?

Yes. Any function can be overloaded. However you cannot override a static member function. Only instance members can be overridden.


Do static variable retain their values even after exiting the function?

Yes. That is the definition of static.


Why static variables in a function have global extent?

A variable declared static outside of a function has a scope the of the source file only. It is not a global variable. A variable declared outside of a function and without the static qualifier would be a global variable.


What is the pupouse of static function?

A static function, not part of a class, is visible only to other code within the same compilation unit, i.e. the same source file. A static function, part of a class, can only operate on static class data, which is per class data as opposed to per instance data.