Skip to content

Commit 44d7cc8

Browse files
main
1 parent a997179 commit 44d7cc8

File tree

18 files changed

+360
-2
lines changed

18 files changed

+360
-2
lines changed

10.String/StringBuffer/program2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public class program2 {
44
public static void main(String[] args) {
5-
System.out.println("Hello world");
5+
66
}
77
}
-1004 Bytes
Binary file not shown.
Binary file not shown.

11.Classes&Objects/AccessSpecifiers/program3.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class employee{
44
int empId = 10;
55
String empName = "Raj";
66
static int salary = 5000;
7+
static int a = 90;
78

89
void empInfo(){
910
System.out.println("empId"+empId);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package Static.StaticBlock;
2+
3+
class demo1{
4+
5+
static int x =10;
6+
static {
7+
System.out.println("In static Block.....!");
8+
}
9+
10+
public static void main(String[] args) {
11+
System.out.println("In main.....!");
12+
}
13+
14+
}
15+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package Static.StaticBlock;
2+
3+
class demo2{
4+
5+
int x =10;
6+
static int y =20;
7+
static {
8+
System.out.println("Static block 1");
9+
}
10+
11+
void fun(){
12+
System.out.println(x);
13+
}
14+
15+
public static void main(String[] args) {
16+
System.out.println("In main.....!");
17+
demo2 obj = new demo2();
18+
19+
// System.out.println(System.identityHashCode(obj));
20+
}
21+
22+
static {
23+
24+
demo2 obj = new demo2();
25+
System.out.println(obj.x);
26+
// System.out.println(System.identityHashCode(obj));
27+
System.out.println("Static block 2");
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package Static.StaticBlock;
2+
3+
class demo3{
4+
5+
static {
6+
System.out.println("Static block");
7+
System.exit(0);
8+
9+
}
10+
11+
public static void main(String[] args) {
12+
System.out.println("In main.....!");
13+
}
14+
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package Static.StaticBlock;
2+
3+
class demo4{
4+
static{
5+
// static int x =10;
6+
System.out.println(x);
7+
}
8+
9+
public static void main(String[] args) {
10+
11+
}
12+
}
13+
14+
/*
15+
16+
Output:
17+
18+
program4.java:5: error: illegal start of expression
19+
static int x =10;
20+
^
21+
program4.java:6: error: <identifier> expected
22+
System.out.println(x);
23+
^
24+
program4.java:6: error: <identifier> expected
25+
System.out.println(x);
26+
^
27+
program4.java:9: error: class, interface, enum, or record expected
28+
public static void main(String[] args) {
29+
^
30+
4 errors
31+
error: compilation failed
32+
33+
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package Static.StaticBlock;
2+
3+
class demo5{
4+
static int x =10;
5+
static {
6+
System.out.println("Static block 1");
7+
}
8+
9+
// public static void main(String[] args) {
10+
// System.out.println("In main 1");
11+
// }
12+
}
13+
14+
class client{
15+
16+
static int y =20;
17+
static {
18+
System.out.println("Static block 2");
19+
}
20+
21+
// public static void main(String[] args) {
22+
// System.out.println("In main 2");
23+
// }
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Static.StaticBlock;
2+
3+
class demo6{
4+
static int x =10;
5+
static {
6+
System.out.println("Static block 1");
7+
}
8+
}
9+
10+
class client6{
11+
12+
static int y =20;
13+
static {
14+
System.out.println("Static block 2");
15+
}
16+
17+
public static void main(String[] args) {
18+
System.out.println("In client main");
19+
demo6 obj = new demo6();
20+
21+
}
22+
23+
static {
24+
System.out.println("Static block 3");
25+
}
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package Static.StaticBlock;
2+
3+
class demo7{
4+
static int x =10;
5+
6+
static{
7+
fun();
8+
System.out.println(x);
9+
}
10+
11+
void fun(){
12+
System.out.println("In fun...!");
13+
}
14+
15+
public static void main(String[] args) {
16+
17+
}
18+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package Static.variableMethods;
2+
3+
class demo1{
4+
int x=10;
5+
private int y =20;
6+
7+
void disp(){
8+
System.out.println(x);
9+
System.out.println(y);
10+
}
11+
}
12+
13+
class client{
14+
public static void main(String[] args) {
15+
// System.out.println(x);
16+
// System.out.println(y);
17+
18+
// disp();
19+
}
20+
}
21+
22+
/*
23+
Output:
24+
program1.java:15: error: cannot find symbol
25+
System.out.println(x);
26+
^
27+
symbol: variable x
28+
location: class client
29+
program1.java:16: error: cannot find symbol
30+
System.out.println(y);
31+
^
32+
symbol: variable y
33+
location: class client
34+
program1.java:18: error: cannot find symbol
35+
disp();
36+
^
37+
symbol: method disp()
38+
location: class client
39+
3 errors
40+
error: compilation failed
41+
*/
42+
43+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package Static.variableMethods;
2+
3+
4+
class demo1{
5+
int x=10;
6+
private int y =20;
7+
8+
void disp(){
9+
System.out.println(x);
10+
System.out.println(y);
11+
}
12+
public static void main(String[] args) {
13+
// System.out.println(x);
14+
// System.out.println(y);
15+
16+
// disp();
17+
}
18+
}
19+
20+
class client{
21+
public static void main(String[] args) {
22+
23+
}
24+
}
25+
26+
/*
27+
Output:
28+
program2.java:13: error: non-static variable x cannot be referenced from a static context
29+
System.out.println(x);
30+
^
31+
program2.java:14: error: non-static variable y cannot be referenced from a static context
32+
System.out.println(y);
33+
^
34+
program2.java:16: error: non-static method disp() cannot be referenced from a static context
35+
disp();
36+
^
37+
3 errors
38+
error: compilation failed
39+
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package Static.variableMethods;
2+
3+
class staticdemo{
4+
static int x =10;
5+
static int y=20;
6+
7+
static void disp(){
8+
System.out.println(x);
9+
System.out.println(y);
10+
}
11+
12+
}
13+
14+
class client{
15+
public static void main(String[] args) {
16+
System.out.println(staticdemo.x);
17+
System.out.println(staticdemo.y);
18+
19+
staticdemo.disp();
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package Static.variableMethods;
2+
3+
class demo4{
4+
int x =10;
5+
static int y =20;
6+
7+
void fun1(){
8+
System.out.println(x);
9+
System.out.println(y);
10+
}
11+
12+
static void fun2(){
13+
System.out.println(y);
14+
}
15+
16+
17+
}
18+
19+
class client{
20+
public static void main(String[] args) {
21+
// demo4.fun1();
22+
demo4.fun2();
23+
}
24+
}
25+
26+
27+
/*
28+
Output:
29+
.\program4.java:21: error: non-static method fun1() cannot be referenced from a static context
30+
demo4.fun1();
31+
^
32+
1 error
33+
*/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Static.variableMethods;
2+
3+
class demo5{
4+
int x =10;
5+
static int y =20;
6+
7+
void fun1(){
8+
System.out.println(x);
9+
System.out.println(y);
10+
}
11+
12+
static void fun2(){
13+
System.out.println(y);
14+
}
15+
16+
17+
}
18+
19+
class client5{
20+
public static void main(String[] args) {
21+
demo5.fun2();
22+
}
23+
}

9.Array/OneDimenArray/ClassCodeArray/program11.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ void fun(){
66
System.out.println("In fun");
77
}
88
public static void main(String[] args) {
9-
fun();
9+
// fun();
1010
}
1111
}
1212

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package OneDimenArray.ClassCodeArray;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
8+
public class program16 {
9+
public static void main(String[] args)throws IOException {
10+
int arr1[] = new int[5];
11+
int arr2[] = new int[8];
12+
int arr3[] = new int[13];
13+
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
int max = Math.max(arr1.length,arr2.length);
16+
int stop = arr1.length;
17+
int x =0;
18+
int y = arr1.length;
19+
for(int i=0;i<max;i++){
20+
if(x<stop){
21+
arr1[x] = Integer.parseInt(br.readLine());
22+
arr3[x] = arr1[x];
23+
}
24+
25+
arr2[i] = Integer.parseInt(br.readLine());
26+
arr3[y] = arr2[i];
27+
x++;
28+
y++;
29+
30+
}
31+
32+
System.out.println();
33+
34+
for(int i=0;i<arr3.length;i++){
35+
System.out.println(arr3[i]);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)