- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMethod.java
More file actions
Latest commit
27 lines (23 loc) · 638 Bytes
/
Copy pathMethod.java
File metadata and controls
27 lines (23 loc) · 638 Bytes
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
/**
* 34. How to create method in java Program
*/
classMethods {
// Constructor method
Methods() {
System.out.println("Constructor method is called when an object of it's class is created");
}
// Main method where program execution begins
publicstaticvoidmain(String[] args) {
staticMethod();
Methodsobject = newMethods();
object.nonStaticMethod();
}
// Static method
staticvoidstaticMethod() {
System.out.println("Static method can be called without creating object");
}
// Non static method
voidnonStaticMethod() {
System.out.println("Non static method must be called by creating an object");
}
}