Skip to content

Commit a267a9a

Browse files
oop 2
1 parent ad825b1 commit a267a9a

15 files changed

Lines changed: 311 additions & 99 deletions

File tree

lectures/17-oop/code/.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lectures/17-oop/code/src/com/kunal/introduction/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.kunal.introduction;
22

33
import java.sql.Struct;
4+
import java.util.ArrayList;
45
import java.util.Arrays;
56

67
public class Main {

lectures/17-oop/code/src/com/kunal/introduction/WrapperExample.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ public static void main(String[] args) {
2323
// when a non primitive is final, you cannot reassign it.
2424
// kunal = new A("new object");
2525

26-
A obj;
26+
A obj = new A("Rnadvsjhv");
2727

28-
for (int i = 0; i < 1000000000; i++) {
29-
obj = new A("Random name");
30-
}
28+
System.out.println(obj);
29+
30+
// for (int i = 0; i < 1000000000; i++) {
31+
// obj = new A("Random name");
32+
// }
3133

3234
}
3335

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.kunal.packages.a;
2+
3+
import static com.kunal.packages.b.Message.message;
4+
5+
public class Greeting {
6+
public static void main(String[] args) {
7+
System.out.println("Hello world");
8+
message();
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.kunal.packages.b;
2+
3+
public class Greeting {
4+
public static void main(String[] args) {
5+
System.out.println(" I am awesome");
6+
}
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.kunal.packages.b;
2+
3+
public class Message {
4+
public static void main(String[] args) {
5+
6+
}
7+
8+
public static void message() {
9+
System.out.println("This course is awesome");
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.kunal.singleton;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Singleton obj1 = Singleton.getInstance();
6+
7+
Singleton obj2 = Singleton.getInstance();
8+
9+
Singleton obj3 = Singleton.getInstance();
10+
11+
// all 3 ref variables are pointing to just one object
12+
}
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.kunal.singleton;
2+
3+
public class Singleton {
4+
private Singleton () {
5+
6+
}
7+
8+
private static Singleton instance;
9+
10+
public static Singleton getInstance() {
11+
// check whether 1 obj only is created or not
12+
if (instance == null) {
13+
instance = new Singleton();
14+
}
15+
16+
return instance;
17+
}
18+
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.kunal.staticExample;
2+
3+
public class Human {
4+
int age;
5+
String name;
6+
int salary;
7+
boolean married;
8+
static long population;
9+
10+
static void message() {
11+
System.out.println("Hello world");
12+
// System.out.println(this.age); // cant use this over here
13+
}
14+
15+
public Human(int age, String name, int salary, boolean married) {
16+
this.age = age;
17+
this.name = name;
18+
this.salary = salary;
19+
this.married = married;
20+
Human.population += 1;
21+
}
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.kunal.staticExample;
2+
3+
import java.util.Arrays;
4+
5+
public class InnerClasses {
6+
7+
static class Test {
8+
String name;
9+
public Test(String name) {
10+
this.name = name;
11+
}
12+
13+
@Override
14+
public String toString() {
15+
return name;
16+
}
17+
}
18+
19+
public static void main(String[] args) {
20+
Test a = new Test("Kunal");
21+
Test b = new Test("Rahul");
22+
23+
System.out.println(a);
24+
25+
// System.out.println(a.name);
26+
// System.out.println(b.name);
27+
}
28+
}
29+
30+
//static class A {
31+
//
32+
//}

0 commit comments

Comments
 (0)