JAVA多态调用案例代码

来源:互联网 发布:安居客网络经纪人 编辑:程序博客网 时间:2024/06/07 20:33

/*
*title:JAVA多态调用演示类代码
*author:chinayaosir
*IDE:JDeveloper version 10.1.1
*function:excel quotesheet with warmart/kmart/cvs  sample code
*/

---------------------------------------------------------------------------------
/*
 * filename:basicqs.java
 */
package userinterfacejsp;
public class basicqs{
    public void GetExcelset( ) {
    System.out.println("pls set excel column set!");
    }

    public void GetExcelFile( ) {
    System.out.println("pls set excel file path!");
    }
    public void savetoExcel( ) {
    System.out.println("pls set excel data!");
    }     
    
}

---------------------------------------------------------------------------------
/*
* filename:warmart.java
*/
package userinterfacejsp;
class warmart extends basicqs{
    public void GetExcelset( ) {
    System.out.println("get excel column set from database table!");
    }
   public void GetExcelFile( ) {
    System.out.println("******Warmark quotesheet******************************");
    System.out.println("excel file= warmark.xls");     
    }
    public void savetoExcel( ) {
    System.out.println("write quotesheet with 120 column data and one photo!");
    System.out.println("write attahchment with 20 coloumn data");    
    System.out.println("write hangtag with 10 coloumn data");    
    }     
}
---------------------------------------------------------------------------------
/*
 * filename:kmart.java
*/
package userinterfacejsp;
class kmart extends basicqs{
    public void GetExcelset( ) {
    System.out.println("get excel column set from database table!");
    }
    
   public void GetExcelFile( ) {
    System.out.println("******Kmark quotesheet********************************");   
    System.out.println("excel file= kmark.xls");
    }
    public void savetoExcel( ) {
    System.out.println("write quotesheet with 100 column data and one photo!");
    System.out.println("write attahchment with 10 coloumn data");  
    }     
}
---------------------------------------------------------------------------------
/*
* filename:cvs.java
*/
package userinterfacejsp;
class cvs extends basicqs{
    public void GetExcelset( ) {
    System.out.println("get excel column set from database table!");
    }
    
   public void GetExcelFile( ) {
    System.out.println("******Warmark quotesheet******************************");
    System.out.println("excel file= cvs.xls");
    }
    public void savetoExcel( ) {
    System.out.println("write quotesheet with 50 column data and one photo!");
    }     
}
---------------------------------------------------------------------------------
/*
 * filename:printqs.java
 */
package userinterfacejsp;
public class printqs{  
    public void excel(basicqs temp){
                temp.GetExcelFile();
                temp.GetExcelset();
                temp.savetoExcel();
    }
    
    public static void main(String args[]) {
        printqs p=new printqs();
        kmart k=new kmart();
        warmart w=new warmart();
        cvs c=new cvs();

        p.excel(k);
        p.excel(w);
        p.excel(c);        
    }

}
---------------------------------------------------------------------------------
program run values:
******Kmark quotesheet********************************
excel file= kmark.xls
get excel column set from database table!
write quotesheet with 100 column data and one photo!
write attahchment with 10 coloumn data
******Warmark quotesheet******************************
excel file= warmark.xls
get excel column set from database table!
write quotesheet with 120 column data and one photo!
write attahchment with 20 coloumn data
write hangtag with 10 coloumn data
******Warmark quotesheet******************************
excel file= cvs.xls
get excel column set from database table!
write quotesheet with 50 column data and one photo!

原创粉丝点击