Skip to content

Commit cd239a3

Browse files
Naveen KhuntetaNaveen Khunteta
authored andcommitted
added code for static and non static
1 parent 35bfee9 commit cd239a3

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed
947 Bytes
Binary file not shown.
1.01 KB
Binary file not shown.
1.47 KB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package JavaSessions;
2+
3+
public class LocalAndGlobalVars {
4+
5+
String name = "Tom";
6+
int age = 25;
7+
8+
public static void main(String[] args) {
9+
10+
LocalAndGlobalVars obj = new LocalAndGlobalVars();
11+
System.out.println(obj.name);
12+
System.out.println(obj.age);
13+
int k =10;
14+
15+
}
16+
17+
18+
public void sum(){
19+
int i = 10; //local var
20+
System.out.println(age);
21+
//System.out.println(k);
22+
}
23+
24+
public void sendMail(){
25+
int j = 20;
26+
}
27+
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package JavaSessions;
2+
3+
public class StaticAndNonStatic {
4+
5+
//class vars, global vars
6+
String name = "Tom";
7+
static int age = 25;
8+
9+
public static void main(String[] args) {
10+
11+
//1. call non static members:
12+
StaticAndNonStatic obj = new StaticAndNonStatic();
13+
obj.sendMail();
14+
System.out.println(obj.name);
15+
16+
obj.sum();//warning
17+
18+
//2. call static members
19+
//a. direct calling:
20+
sum();
21+
System.out.println(age);
22+
//b. call by class name:
23+
StaticAndNonStatic.sum();
24+
System.out.println(StaticAndNonStatic.age);
25+
26+
}
27+
28+
public void sendMail(){
29+
System.out.println("send mail method");
30+
}
31+
32+
public static void sum(){
33+
System.out.println("sum method");
34+
}
35+
36+
37+
38+
39+
}

src/JavaSessions/WrapperClass.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package JavaSessions;
2+
3+
import java.util.ArrayList;
4+
5+
public class WrapperClass {
6+
7+
public static void main(String[] args) {
8+
9+
//1. String to int :
10+
String x = "100";
11+
System.out.println(x+20);
12+
13+
int i = Integer.parseInt(x); //100
14+
System.out.println(i+20);
15+
16+
// String h = "100A";
17+
// int g = Integer.parseInt(h);
18+
// System.out.println(g);//NumberFormatException: For input string: "100A
19+
20+
21+
//2. String to double:
22+
String y = "12.33";
23+
System.out.println(y+20);
24+
25+
double d = Double.parseDouble(y);
26+
System.out.println(d+10.22);
27+
28+
//3. int to String:
29+
int k = 100;
30+
System.out.println(k+20);
31+
String p = String.valueOf(k); //"100"
32+
System.out.println(p+20);
33+
34+
35+
String tr = "your total amount is : 500";
36+
37+
ArrayList<Integer> ar = new ArrayList<Integer>();
38+
}
39+
40+
}

0 commit comments

Comments
 (0)