나는 책 클래스가 :추상 클래스에 대해 DataOutputStream 메서드를 만들고 하위 클래스에이 메서드를 사용할 수 있습니까?
public abstract class Book
{
private String author, title;
private int pages;
private double price;
Book next;
public Book(String f, String t, int sider, double p)
{
author = a;
title = t;
pages = pa;
price = p;
next = null;
}
그리고 서브 클래스 등 소설, 교과서와 같은. DataOutputStream을 사용하여 파일에이 메서드를 작성해야합니다. 아래에서이 코드를 만들었지 만 올바른 경로에 있는지 확실하지 않습니다. 서브 클래스에서 어떻게 사용합니까?
class Textbook extends Book
{
private String subject;
public Textbook(String a, String t,int pa, double p, String sub)
{
super(a, t, pa, p);
subject = sub;
}
어떤 아이디어 :
public void writeObjectToFile()
{
try
{
FileOutputStream fos = new FileOutputStream("book.something");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeUTF(author);
dos.writeUTF(title);
dos.writeInt(pages);
dos.writeDouble(price);
}catch (IOException e){
e.printStackTrace();
}
}
는의 교과서 클래스는이처럼 가정 해 봅시다? ObjectOutputStream
을 사용할 수 없습니다.
정말 고마워요. 제가 누락 된 부분입니다. 정말 도움이되었습니다. – user938773