Skip to content

Commit 40d0cf8

Browse files
oop-1
1 parent e841442 commit 40d0cf8

13 files changed

Lines changed: 299 additions & 0 deletions

File tree

‎lectures/17-oop/code/.idea/.gitignore‎

Lines changed: 3 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/.idea/description.html‎

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

‎lectures/17-oop/code/.idea/encodings.xml‎

Lines changed: 6 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/.idea/misc.xml‎

Lines changed: 12 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/.idea/modules.xml‎

Lines changed: 8 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/.idea/project-template.xml‎

Lines changed: 3 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/.idea/vcs.xml‎

Lines changed: 6 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/code.iml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.kunal.introduction;
2+
3+
import java.sql.Struct;
4+
import java.util.Arrays;
5+
6+
public class Main {
7+
public static void main(String[] args) {
8+
// store 5 roll nos
9+
int[] numbers = new int[5];
10+
11+
// store 5 names
12+
String[] names = new String[5];
13+
14+
// data of 5 students: {roll no, name, marks}
15+
int[] rno = new int[5];
16+
String[] name = new String[5];
17+
float[] marks = new float[5];
18+
19+
Student[] students = new Student[5];
20+
21+
// just declaring
22+
// Student kunal;
23+
// kunal = new Student();
24+
25+
Student kunal = new Student(15, "Kunal Kushwaha", 85.4f);
26+
Student rahul = new Student(18, "Rahul Rana", 90.3f);
27+
28+
// kunal.rno = 13;
29+
// kunal.name = "Kunal Kushwaha";
30+
// kunal.marks = 88.5f;
31+
32+
33+
// kunal.changeName("Shoe lover");
34+
// kunal.greeting();
35+
36+
//
37+
System.out.println(kunal.rno);
38+
System.out.println(kunal.name);
39+
System.out.println(kunal.marks);
40+
41+
Student random = new Student(kunal);
42+
System.out.println(random.name);
43+
44+
Student random2 = new Student();
45+
System.out.println(random2.name);
46+
47+
Student one = new Student();
48+
Student two = one;
49+
50+
one.name = "Something something";
51+
52+
System.out.println(two.name);
53+
54+
}
55+
}
56+
57+
// create a class
58+
// for every single student
59+
class Student {
60+
int rno;
61+
String name;
62+
float marks = 90;
63+
64+
// we need a way to add the values of the above
65+
// properties object by object
66+
67+
// we need one word to access every object
68+
69+
void greeting() {
70+
System.out.println("Hello! My name is " + this.name);
71+
}
72+
73+
void changeName(String name) {
74+
this.name = name;
75+
}
76+
77+
Student (Student other) {
78+
this.name = other.name;
79+
this.rno = other.rno;
80+
this.marks = other.marks;
81+
}
82+
83+
Student () {
84+
// this is how you call a constructor from another constructor
85+
// internally: new Student (13, "default person", 100.0f);
86+
this (13, "default person", 100.0f);
87+
}
88+
89+
90+
// Student arpit = new Student(17, "Arpit", 89.7f);
91+
// here, this will be replaced with arpit
92+
Student (int rno, String name, float marks) {
93+
this.rno = rno;
94+
this.name = name;
95+
this.marks = marks;
96+
}
97+
98+
}
99+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.kunal.introduction;
2+
3+
public class WrapperExample {
4+
public static void main(String[] args) {
5+
// int a = 10;
6+
// int b = 20;
7+
//
8+
// Integer num = 45;
9+
10+
Integer a = 10;
11+
Integer b = 20;
12+
13+
swap(a, b);
14+
15+
System.out.println(a + " " + b);
16+
17+
// final int bonus = 2;
18+
// bonus = 3;
19+
20+
final A kunal = new A("Kunal Kushwaha");
21+
kunal.name = "other name";
22+
23+
// when a non primitive is final, you cannot reassign it.
24+
// kunal = new A("new object");
25+
26+
A obj;
27+
28+
for (int i = 0; i < 1000000000; i++) {
29+
obj = new A("Random name");
30+
}
31+
32+
}
33+
34+
static void swap(Integer a, Integer b) {
35+
Integer temp = a;
36+
a = b;
37+
b = temp;
38+
}
39+
40+
}
41+
42+
class A {
43+
final int num = 10;
44+
String name;
45+
46+
public A(String name) {
47+
// System.out.println("object created");
48+
this.name = name;
49+
}
50+
51+
@Override
52+
protected void finalize() throws Throwable {
53+
System.out.println("Object is destroyed");
54+
}
55+
}

0 commit comments

Comments
 (0)