-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleIntro_main.java
More file actions
39 lines (34 loc) · 2.98 KB
/
ExampleIntro_main.java
File metadata and controls
39 lines (34 loc) · 2.98 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
// class - blueprint for an object, contains instance variables (data members, data, values, states) and methods (instructions, behaviours)
// class modifiers can only be public, final, abstract, however inner classes can have other modifiers
// access modifier public - anyone can access
// access modifier protected - subclasses can access regardless of package
// access modifier default (no modifier) - only the package can access
// access modifier private - only the class can access
// non access modifier static - variable - exists independently from class object, only single copy exists regardless of number of class objects created
// non access modifier static - method - exists independently from class object, has no reference to class objects variables, must be passed in via parameters
// non access modifier final - variable - value cannot be changed
// non access modifier final - method - cannot be overridden
// non access modifier final - class - cannot be inherited
// non access modifier abstract - method - declared not defined (no body), must be implemented if inherited
// non access modifier abstract - class - must be inherited, cannot be made an object alone
// void - no return type (procedure)
public class ExampleIntro_Main
{
public static void main(String[] args) // main method, application entry point, must be public static for the jvm to see it and invoke it, string array parameter is for command line arguments
{
String localvariable1 = "localvariable1"; // create variable (type name = value)
String localvariable2 = "localvariable2"; // local variable as created inside a method, can only be accessed inside this method
String localvariable3 = "localvariable3";
ExampleIntro referencevariable; // create reference variable of the type class in stack memory
referencevariable = new ExampleIntro(); // create new instance of class (object) inside heap memory via the class constructor, links to the reference variable in the stack memory
referencevariable.method1(localvariable1); // call method from the object passing it local string parameter
referencevariable.method2(localvariable1, localvariable2); // call method from the object passing it two local string parameters
referencevariable.method3(localvariable1, localvariable2, localvariable3); // call method from the object passing it three local string parameters
referencevariable.method4(); // call method from the object, passing it nothing as nothing is expected
referencevariable.method5(); // call method from the object, passing it nothing as nothing is expected
System.out.println(referencevariable.IfElseOddOrEven(101)); // print what this function method returns when called with this parameter
System.out.println(referencevariable.IfElseOddOrEven(102)); // print what this function method returns when called with a different parameter
referencevariable.ForLoop(1, 3); // call this method and pass it two parameters
referencevariable.WhileLoop(101, 103); // call this method and pass it two parameters
}
}