-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMyAwesomProgram.java
More file actions
51 lines (44 loc) · 1.32 KB
/
Copy pathMyAwesomProgram.java
File metadata and controls
51 lines (44 loc) · 1.32 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
// We make field definitions not at the class level but at the object level
// Notice the user is defined within a method
public class MyAwesomeProgram
{
public static void main(String [] args)
{
User user = new User();//not a field not a class but a loc var to the main meth
user.firstName= "Bob";
user.lastName= "Smith";
}
}
//<----------------------------------CHANGING THE ABOVE CODE TO THE BOTTOM CODE TO CALL THE OUTPUT METHOD ON USER!------------------------------------------->
public class MyAwesomeProgram
{
public static void main(String [] args)
{
User user = new User();//not a field not a class but a loc var to the main meth
user.firstName= "Bob";
user.lastName= "Smith";
user.output(7);
//prints:
//Bob Smith
//Bob Smith
//Bob Smith
//Bob Smith
//Bob Smith
//Bob Smith
//Bob Smith
}
}
//<-------------CHANGING THE ABOVE CODE TO THE BOTTOM CODE TO CALL THE OUTPUT METHOD ON USER FROM A STRING VARIABLE!------------->
public class MyAwesomeProgram
{
public static void main(String [] args)
{
User user = new User();
user.firstName= "Bob";
user.lastName= "Smith";
String message = user.output();
System.out.println(message);
}
}
//Remember whenever I have the keyword void within my method declaration
//I can still use the return keyword within it but I cannot return a value.