-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic and Non-Static functions .java
More file actions
56 lines (49 loc) · 1.18 KB
/
Static and Non-Static functions .java
File metadata and controls
56 lines (49 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//https://classroom.udacity.com/courses/ud282
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
class ForFunctionCalls{
/**
* What static and non statc function mean?
* What static ans non static function mean here?
* Static function can be called without their object.
**/
int callfunc1()
{
return 5;
}
static int callfunc2()
{
return 10;
}
}
//all the function inside this [ calss containg main ] will be static
//because there will no object of this call for calling those function
class JavaPractice
{
/**
* This will always be
* public static void main (String[] args)
**/
public static void main (String[] args)
{
System.out.println(myfunc());
ForFunctionCalls obj=new ForFunctionCalls();
System.out.println(obj.callfunc1());
System.out.println(obj.callfunc2());
System.out.println("This one have no object:"+ForFunctionCalls.callfunc2());
/**
* Will give error becouse have no object
* System.out.println("This one have no object:"+ForFunctionCalls.callfunc1());
**/
}
/**
* why this must be static?
* Should be because inside the class of main
**/
static int myfunc()
{
return 10;
}
}