-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoops2.java
More file actions
38 lines (29 loc) · 1.06 KB
/
oops2.java
File metadata and controls
38 lines (29 loc) · 1.06 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
public class oops2 {
// Static method
static void myStaticMethod() {
System.out.println("Static methods can be called without creating objects");
}
// Public method
public void myPublicMethod() {
System.out.println("Public methods must be called by creating objects");
}
// Create a fullThrottle() method
public void fullThrottle() {
System.out.println("The car is going as fast as it can!");
}
// Create a speed() method and add a parameter
public void speed(int maxSpeed) {
System.out.println("Max speed is: " + maxSpeed);
}
// Inside main, call the methods on the myCar object
// Main method
public static void main(String[] args) {
myStaticMethod(); // Call the static method
// myPublicMethod(); This would compile an error
oops2 myObj = new oops2(); // Create an object of Main
myObj.myPublicMethod(); // Call the public method on the object
oops2 myCar = new oops2(); // Create a myCar object
myCar.fullThrottle(); // Call the fullThrottle() method
myCar.speed(200);
}
}