File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /.class
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ public class Method {
4+ public static void main (String [] args ) {
5+ System .out .println ("Calling Simple Method" );
6+ simpleMethod ();
7+ }
8+
9+ public static void simpleMethod () {
10+ System .out .println ("Simple Method" );
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ // Call by Value
4+
5+ public class ParamMethod1 {
6+ public static void main (String [] args ) {
7+ int a = 10 ;
8+ int b = 20 ;
9+
10+ System .out .println ("Before swapping, a: " + a + " b: " + b );
11+
12+ // Invoke the swap method
13+ swapFunction (a , b );
14+ System .out .println ("After swapping(outside), a: " + a + " b: " + b );
15+ }
16+
17+ public static void swapFunction (int a , int b ) {
18+ System .out .println ("Before swapping(Inside), a: " + a + " b: " + b );
19+
20+ // Swap n1 with n2
21+ int c = a ;
22+ a = b ;
23+ b = c ;
24+
25+ System .out .println ("After swapping(Inside), a: " + a + " b: " + b );
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ public class StaticModifier {
4+ // Static Variables
5+ public static int a = 10 ;
6+ public static int b = 20 ;
7+
8+ public static void sum () {
9+ // Local variable to sum function
10+ int z = a + b ;
11+
12+ System .out .println ("Sum: " + z );
13+ }
14+
15+ public void diff () {
16+ // Local variable to diff function
17+ int z = a - b ;
18+
19+ a = 100 ;
20+ b = 200 ;
21+
22+ System .out .println ("Diff: " + z );
23+ }
24+
25+ public static void main (String [] args ) {
26+ // Instance of the class
27+ StaticModifier obj = new StaticModifier ();
28+
29+ // Access static variables
30+ System .out .println ("a: " + a );
31+ System .out .println ("b: " + b );
32+
33+ // Call the sum function
34+ sum ();
35+
36+ // Call the diff function
37+ obj .diff ();
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments