0
我剛剛學習如何在Java中使用繼承。此程序的目的是編寫包含某些日誌條目信息的類,並提供設置和獲取適當信息的方法。請讓我知道是否需要更正。Java中的繼承
ArithmeLog.java
//super class ArithmeLog with three functions to capture three instances
import java.util.*;
import java.text.*;
public class ArithmeLog {
public ArithmeLog() {
}
public void captid1(String a) {
System.out.println("");
}
public void captid2(String SongName) {
System.out.println("");
}
public void Date() {
Date capttim = new Date();
SimpleDateFormat formt = new SimpleDateFormat
("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
System.out.println("Time is : " +
formt.format(capttim));
}
}
SongLog.java
//class SongLog which inheriting ArithmeLog class
import java.util.*;
import java.text.*;
public class SongLog extends ArithmeLog {
public SongLog() {
super();
System.out.println("");
}
@Override
public void captid1(String SongID) {
System.out.println("SongID is: "+SongID);
}
@Override
public void captid2(String SongName) {
System.out.println("Song name is: "+SongName);
}
@Override
public void Date() {
Date capttim = new Date();
SimpleDateFormat formt = new SimpleDateFormat
("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
System.out.println(" Date and time is : " +
formt.format(capttim));
}
}
AdLog.java
// AdLog class which inheriting ArithmeLog class
import java.util.*;
import java.text.*;
public class AdLog extends ArithmeLog {
public AdLog() {
super();
System.out.println("");
}
@Override
public void captid1(String AdvertisementID) {
System.out.println("AdvertisementID is:"+AdvertisementID);
}
@Override
public void captid2(String AdvertiserID) {
System.out.println("AdvertiserID is:"+AdvertiserID);
}
@Override
public void Date() {
Date capttim = new Date();
SimpleDateFormat formt = new SimpleDateFormat
("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
System.out.println(" Date and time is : " +
formt.format(capttim));
}
}
Mainpgm.java
// main class creating objects of classes and calling methods
public class Mainpgm {
public static void main(String[] args) {
//creating first object of classes
ArithmeLog animal = new ArithmeLog();
AdLog ao1 = new AdLog();
SongLog so1 = new SongLog();
System.out.println();
ao1.captid1("1");
ao1.captid2("7");
ao1.Date();
so1.captid1("1");
so1.captid2("songg1");
so1.Date();
//creating second object of classes
AdLog ao2 = new AdLog();
SongLog so2 = new SongLog();
ao2.captid1("2");
ao2.captid2("ad2");
ao2.Date();
so2.captid1("2");
so2.captid2("songg2");
so2.Date();
//creating third object of classes
AdLog ao3 = new AdLog();
SongLog so3 = new SongLog();
ao3.captid1("3");
ao3.captid2("ad3");
ao3.Date();
so3.captid1("6");
so3.captid2("songg3");
so3.Date();
}
}
和錯誤是什麼? –
你使用IDE嗎?這是一個編譯錯誤?什麼線?它說什麼? – MaxG
歡迎來到Stack Overflow!您可能會從使用良好的調試工具或技術中受益。使用調試工具,您可以逐行瀏覽代碼並查看它正在執行的操作。或者,您可以使用某些技術(如添加打印語句或警報)來跟蹤程序的執行情況,而無需調試器。更多幫助信息:[如何調試小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – shoover