-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctions.java
More file actions
30 lines (26 loc) · 1.04 KB
/
Functions.java
File metadata and controls
30 lines (26 loc) · 1.04 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
public class Functions {
private String name;
// all function definitions must be inside a class
// we also call functions methods.
public static void main(String[] args) {
String fullNames = getFullNames("John", "Doe");
System.out.println("FullNames: " + fullNames);
}
// method/function with arguments
public static String getFullNames(String firstName, String lastName) {
return firstName + " " + lastName;
}
// non-static methods: can only be run on objects
// can access and alter the field of the object
// These methods can only be called on class instance
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// Summary
// Every Java method has to be within a class
// Static methods belong to a class while non-static methods belong to objects
// All parameters to functions are passed by value, primitives content is copied, while objects are not copied and some would say 'passed by reference'
}