File tree Expand file tree Collapse file tree 5 files changed +148
-0
lines changed Expand file tree Collapse file tree 5 files changed +148
-0
lines changed Original file line number Diff line number Diff line change
1
+ package day14 ;
2
+
3
+ public class MethodOverloading {
4
+ void show (String msg , String str ){
5
+ System .out .println (msg +" " +str );
6
+ }
7
+ void show (String name ){
8
+ System .out .println (" I'm a Student. My name is " +name );
9
+ }
10
+ }
11
+ class Name {
12
+ public static void main (String [] args ) {
13
+ MethodOverloading m = new MethodOverloading ();
14
+ m .show ("Hey " ,"Buddy !" );
15
+ m .show ("Shitanshu" );
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ package day14 ;
2
+ //Single Inheritance//
3
+ public class Parent {
4
+ void Parent () {
5
+ System .out .println ("Hello from Parent!" );
6
+ }
7
+ }
8
+ class Child extends Parent {
9
+ void Child (){
10
+ System .out .println ("Hello from Child!" );
11
+ }
12
+
13
+ public static void main (String [] args ) {
14
+ Child c = new Child ();
15
+ c .Parent ();
16
+ c .Child ();
17
+ }
18
+ }
19
+ // Multilevel Inheritance
20
+ class GP {
21
+ void GP (){
22
+ System .out .println ("Hello from GP !" );
23
+ }
24
+ }
25
+ class PR extends GP {
26
+ void PR (){
27
+ System .out .println ("Hello from PR !" );
28
+ }
29
+ }
30
+ class CH extends PR {
31
+ void CH (){
32
+ System .out .println ("Hello from CH !" );
33
+ }
34
+
35
+ public static void main (String [] args ) {
36
+ CH c = new CH ();
37
+ c .GP ();
38
+ c .PR ();
39
+ c .CH ();
40
+ }
41
+ }
42
+ //Hiearchical Inheritance
43
+ class GrandParent {
44
+ void GrandParnt (){
45
+ System .out .println ("Hello from GrandParent !" );
46
+ }
47
+ }
48
+ class Parent1 extends GrandParent {
49
+ void Parent1 (){
50
+ System .out .println ("Hello from Parent1 !" );
51
+ }
52
+ }
53
+ class Parent2 extends GrandParent {
54
+ void Parent2 (){
55
+ System .out .println ("Hello from Parent2 !" );
56
+ }
57
+
58
+ public static void main (String [] args ) {
59
+ Parent1 p1 = new Parent1 ();
60
+ p1 .GrandParnt ();
61
+ p1 .Parent1 ();
62
+ Parent2 p2 = new Parent2 ();
63
+ p2 .GrandParnt ();
64
+ p2 .Parent2 ();
65
+ }
66
+ }
Original file line number Diff line number Diff line change
1
+ package day14 ;
2
+ import java .util .Scanner ;
3
+
4
+ public class StudMethod {
5
+ String name ;
6
+ void Student () {
7
+ Scanner sc = new Scanner (System .in );
8
+ System .out .println ("Please Enter Your Name : " );
9
+ name =sc .nextLine ();
10
+ showName ();
11
+ }
12
+ void showName (){
13
+ System .out .println ("Namaste " +name );
14
+ }
15
+ }
16
+ class MainClas {
17
+ public static void main (String [] args ) {
18
+ StudMethod s =new StudMethod ();
19
+ s .Student ();
20
+ //s.showName();
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ package day14 ;
2
+ import java .util .Scanner ;
3
+
4
+ public class StudentM {
5
+ String name ;
6
+ StudentM (String n ){
7
+ name =n ;
8
+ }
9
+ StudentM (){
10
+ Scanner sc =new Scanner (System .in );
11
+ System .out .println ("Enter Your Name :" );
12
+ name =sc .nextLine ();
13
+ }
14
+ void showName (){
15
+ System .out .println ("Hey " +name );
16
+ }
17
+ }
18
+ class MainclaSS {
19
+ public static void main (String [] args ) {
20
+ StudentM st = new StudentM ("Human" );
21
+ st .showName ();
22
+ StudentM st1 =new StudentM ();
23
+ st1 .showName ();
24
+
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package day14 ;
2
+
3
+ public class ThisPointer {
4
+ void showOne (){
5
+ System .out .println ("Hello from showOne" );
6
+ this .showTwo ();
7
+ }
8
+ void showTwo (){
9
+ System .out .println ("Hello from showTwo" );
10
+ }
11
+ }
12
+ class MainClass {
13
+ public static void main (String [] args ) {
14
+ ThisPointer t = new ThisPointer ();
15
+ t .showOne ();
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments