Sem 5‎ > ‎JAVA LAB‎ > ‎

Px10: WAP to implement multiple inheritance using Interfaces.

posted Aug 22, 2012, 10:14 AM by Neil Mathew   [ updated Aug 22, 2012, 10:15 AM ]

SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//Interface
interface FirstNameShow
{
String fname = "Neil";
void showFirst();
}
 
//Interface #2
interface LastNameShow
{
String lname = "Mathew";
void showLast();
}
 
//Normal Class
class ID_GetShow
{
int idnum;
 
void getnumber(int n)
        {
        idnum=n;
        }
 
void putnumber()
        {
        System.out.println("ID Number:"+idnum);
        }
 
}
 
class InterfaceExample extends ID_GetShow 
implements FirstNameShow, LastNameShow
{ 
public void showFirst()
        {
        System.out.println("First Name: "+fname);
        } 
public void showLast()
        {
        System.out.println("Last Name: "+lname);
        } 
 
public static void main(String args[])
        {
 
        InterfaceExample a=new InterfaceExample();
        a.getnumber(15);
        a.showFirst();
        a.showLast();
        a.putnumber();
        }
}
 




OUTPUT:


C:\Java 1.6\jdk1.6.0_30\bin>cd src3


C:\Java 1.6\jdk1.6.0_30\bin\src3>javac InterfaceExample.java

 

C:\Java 1.6\jdk1.6.0_30\bin\src3>java InterfaceExample

 

First Name: Neil

Last Name: Mathew

ID Number:15

 


Comments