[Go to site: main page, start]

0% found this document useful (0 votes)
2 views1 page

Method Overloading Example

The document contains a Java code snippet demonstrating method overloading and overriding through a parent class 'Stud' and a child class 'School'. It showcases how to use polymorphism with dynamic dispatch and compile-time method resolution. The output of the program includes greetings to students and displays values based on the method calls made.

Uploaded by

rishavdari93
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Method Overloading Example

The document contains a Java code snippet demonstrating method overloading and overriding through a parent class 'Stud' and a child class 'School'. It showcases how to use polymorphism with dynamic dispatch and compile-time method resolution. The output of the program includes greetings to students and displays values based on the method calls made.

Uploaded by

rishavdari93
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Add ()

float X = Add(35.15, 10.10) ;


int Y = Add(12, 20) ;
int P = Add(10, 20, 30) ;

//Parent Class
class Stud{

public void Show() {


[Link](“Hi Students”) ;
}

//Overloaded method – Same name but different parameter


Public void Show(int S) {
[Link](“Hi Students of Semester “ + S) ;
}
}
//Child Class
class School extends Stud{
//Overrides Parent Class method (Runtime polymorphism)
public void Show(int C){
[Link](“Child Class Value: “ + C) ;
}
}

Public class Main{


Public static void main(String[] args){
Stud P = new Stud() ;
School M = new School() ;

//Polymorphic Object (Dynamic Dispatch)


Stud PMO = new School() ;

//Method overloading (Compile Time)


[Link]() ;
[Link](4) ;

//Method Overriding (Runtime)


[Link](20) ;

//Polymorphism action
[Link](30) ;

}
}
Output:
Hi Students
His Students of Semester 4
Child Class Value: 20
Child Class Value: 30

You might also like