AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-keyword: can we create object for the static method in java?

Could you plz explain object creation concept with sample code.

corejava x 353
keyword x 9
Posted On : 2016-09-08 18:57:34.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
267150
up-rate
-3
down-rate

Answers


we never create object for a method, Object is all about class and class may have static or non-static properties and methods.

static method:
-------------------
A static method belongs to the class rather than object of a class.
A static method can be invoked without the need for creating an instance of a class.
static method can access static data member and can change the value of it.

Note:
--------------------------
We can call static methods directly by its name or with class name or by making the instance of its class(optional).


class A{
public static void print(){
System.out.println("Hi");
}
public static void main(String s1[]){
print();
A.print();
new A().print();
}
}

Output:
---------------------
Hi
Hi
Hi

Posted On : 2016-09-09 15:54:56
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222688
Reply This Thread
up-rate
3
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in