0% found this document useful (0 votes)
6 views

Poly

The document defines classes A, B, and C where B extends A and C extends B. The classes contain methods with the same name but different parameters. The main method creates objects of these classes and calls their test methods to demonstrate polymorphism.

Uploaded by

Nassim Makdi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Poly

The document defines classes A, B, and C where B extends A and C extends B. The classes contain methods with the same name but different parameters. The main method creates objects of these classes and calls their test methods to demonstrate polymorphism.

Uploaded by

Nassim Makdi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

package Rattrappage2014 ;

class A {
public void test (int i1, int i2) {
System.out.println ("A.test(int, int)") ;
}
}

class B extends A {
public void test (float f, int a) {
System.out.println ("B.test(float, int)") ;
}
public void test (float f1, float f2) {
System.out.println ("B.test(float, float)") ;
}
public void test (int i, float f) {
System.out.println ("B.test(int, float)") ;
}
}

class C extends B {
public void test (int i1, int i2) {
System.out.println ("B.test(int, int)") ;
}
public void test (int a, double d) {
System.out.println ("C.test (int, double)") ;
}
public void test (float f1, float f2) {
System.out.println ("B.test(float, float)") ;
}
public void test (double d1, double d2) {
System.out.println ("C.test (double, double)") ;
}
}

public class Polymorphisme


{ public static void main (String args[])
{
A aA = new A () ;
A aC = new C () ;
B bC = new C () ;
C cC = new C () ;

bC.test (0, 0) ; //instruction 1


bC.test (5f, 0l) ; //instruction 2
cC.test (0f, 0) ; //instruction 3
aC.test ((byte)5, 10) ; //instruction 4
aA.test (0.f, 0.f) ; //instruction 5
cC.test (1.f, 0) ; //instruction 6
}
}

FIGURE 1. Polymorphisme

You might also like