Package com. test;
/**
* Rubber
**/
Public abstract class eraser {
Public abstract void erase ();
}
Package com. test;
/**
* Pencil
**/
Public abstract class penpencil {
Public abstract void wirte ();
}
Package com. test;
/**
* Make a functional class that includes both pencil and eraser.
* (It can be fully implemented using interfaces. Here we only assume that this situation is used to simulate multi-inheritance)
**/
Public class pencilwitheraser {
Private mypenpencil penpencil = new mypenpencil ();
Private myeraser eraser = new myeraser ();
/**
*
* Inherits the pencil Function
*
**/
Private class mypenpencil extends penpencil {
@ Override
Public void wirte (){
System. Out. println ("use to wirte ");
}
}
/* Write a class with both pen and rubber Functions
**/
Private class myeraser extends eraser {
@ Override
Public void erase (){
System. Out. println ("use to erase ");
}
}
/*
* Methods of this class
**/
Public void wirte (){
Penpencil. wirte ();
}
Public void eraser (){
Eraser. Erase ();
}
}
Test class
Package com. test;
Public class test {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Pencilwitheraser = new pencilwitheraser ();
Pencilwitheraser. wirte ();
Pencilwitheraser. Eraser ();
}
}
This class has both pen and eraser functions. Simulate Java multi-inheritance.