English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Also, what does the module type represents if omitted or not in "public double void myFunction()" or "public void myFunction()"?

2007-02-14 07:50:48 · 3 answers · asked by ◄|| G ||► 6 in Computers & Internet Programming & Design

3 answers

main is a special function/method in java...and it is static...

A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated. Static method therefore is also called a class method. There are situtations where you want to not have to create an object to access a certain method. It has to do with object oriented logic.

a. In a file context, static function means that the function can be called only within the file scope.
b. In a class context, it means that you can invoke a method of a class without having to instantiate an object. However note that in static methods, you can only manipulate variables that are declared as static, and not other variables.


Now I am not sure what you meant by module, but "public double void myFunction()" or "public void myFunction()", the first one is wrong syntax. The keyword public is followed by the type of thing the method/function is going to return. So if it returns an integer, you would say "public integer myFunction()". But if it does not return anything, it does not mean you can omit the return type. In that case you say void, "public void myFunction()". So basically in this case function does something but does not return a value to whichever object called the function.

So in first case you could have said something like

integer x = myClass.myFunction();

where myClass is the object of the class in which myFunction is defined. But if myFunction has void return type, then you can say

myClass.myFuntion();

but not save it into x because myFunction does not return anything.

So "public double void myFunction()" means that you are returning a double but you followed it by void meaning you are not returning anything. That does not make sense and java will throw an error....

I hope things make sense.

2007-02-14 08:11:36 · answer #1 · answered by Omair 2 · 0 0

a function (eg add or find_lowest or main) is static or not. If static, then each time the function is called the variables defined there retain values. eg if in a function you do a = 5 then a = a +1. then in the next call the value will be 6 to start with. Cool. But as main is called usually once it does not matter if main is static or not (in high level programming you might need to tell whether main is static or not??? I am not sure when is main called more then once by the OS)

2007-02-14 08:01:10 · answer #2 · answered by charles.2345 1 · 0 0

In public status void main, Static - means that the Main can be called without creating an instance of the container class and this is how your program execution starts, even though your main resides in a class and you dont invoke main() by creating an object of that class.

2007-02-14 07:57:45 · answer #3 · answered by Aryan 2 · 0 0

fedest.com, questions and answers