Skip to content

Commit c0b2212

Browse files
Naveen KhuntetaNaveen Khunteta
authored andcommitted
added code for super, this and constructor concept
1 parent 00ea16e commit c0b2212

8 files changed

Lines changed: 100 additions & 0 deletions

File tree

bin/JavaSessions/A.class

905 Bytes
Binary file not shown.

bin/JavaSessions/B.class

691 Bytes
Binary file not shown.
1.2 KB
Binary file not shown.
809 Bytes
Binary file not shown.

src/JavaSessions/A.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package JavaSessions;
2+
3+
public class A {
4+
5+
public A(){
6+
System.out.println("parent class const");
7+
}
8+
9+
public A(int i){
10+
System.out.println("parent class const with value of i "+ i);
11+
}
12+
13+
public A(int i, int j){
14+
System.out.println("parent class const with value of i "+ i);
15+
System.out.println("parent class const with value of j "+ j);
16+
17+
}
18+
19+
20+
21+
}

src/JavaSessions/B.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package JavaSessions;
2+
3+
public class B extends A{
4+
5+
public B(){
6+
super();
7+
}
8+
9+
public B(int i){
10+
super(i);
11+
}
12+
13+
public B(int i, int j){
14+
super(i,j);
15+
}
16+
17+
18+
public static void main(String args[]){
19+
B obj = new B();
20+
B obj1 = new B(10);
21+
B obj2 = new B(10,20);
22+
23+
24+
}
25+
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package JavaSessions;
2+
3+
public class ConstructorConcept {
4+
5+
public ConstructorConcept() {
6+
System.out.println("Default const");
7+
}
8+
9+
public ConstructorConcept(int i) {
10+
System.out.println("single param constructor");
11+
System.out.println("the value of i " + i);
12+
}
13+
14+
public ConstructorConcept(int i, int j) {
15+
System.out.println("two params constructor");
16+
System.out.println("the value of i " + i);
17+
System.out.println("the value of j " + j);
18+
19+
}
20+
21+
public static void main(String[] args) {
22+
23+
ConstructorConcept obj = new ConstructorConcept();
24+
ConstructorConcept obj1 = new ConstructorConcept(10);
25+
ConstructorConcept obj2 = new ConstructorConcept(10, 20);
26+
27+
}
28+
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package JavaSessions;
2+
3+
public class ConstructorWithThisKeyword {
4+
5+
//class vars
6+
String name;
7+
int age;
8+
9+
public ConstructorWithThisKeyword(String name, int age){
10+
this.name = name;
11+
this.age = age;
12+
13+
System.out.println(name);
14+
System.out.println(age);
15+
16+
}
17+
18+
19+
20+
public static void main(String[] args) {
21+
ConstructorWithThisKeyword obj = new ConstructorWithThisKeyword("Tom",30);
22+
}
23+
24+
}

0 commit comments

Comments
 (0)