Skip to content

Commit 9dd2a94

Browse files
authored
Method Overloading
1 parent b8aa47e commit 9dd2a94

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed

day14/MethodOverloading.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

day14/Parent.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
}

day14/StudMethod.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

day14/StudentM.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

day14/ThisPointer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)