Lec: 23 | JAVA
LEC:23
Polymorphism in JAVA | Function Overloading | Function Overiding in JAVA | Compile time vs Run time Polymorphism in JAVA
Source Code:
package oops;
import java.util.Scanner;
class Student {
int sum(int a,int b)
{
return (a+b);
}
int sum(int a,int b,int c)
{
return (a+b+c);
}
float sum(int a,float b)
{
return (a+b);
}
float sum(float a,int b)
{
return (a+b);
}
//overiding
void display()
{
System.out.println("I am Student class");
}
}
class Mark extends Student
{
void display()
{
System.out.println("I am Marks class");
}
}
public class OOPS {
public static void main(String[] args) {
Student O1=new Student();
System.out.println("The addition of two numbers is : "+O1.sum(5, 8));
System.out.println("The addition of two numbers is : "+O1.sum(5, 8,7));
System.out.println("The addition of two numbers is : "+O1.sum(5, 8.6f));
System.out.println("The addition of two numbers is : "+O1.sum(7.8f, 8));
Mark O3=new Mark();
O3.display();
}
}
Comments
Post a Comment