Define author book class

Four classes are defined: Publishing House class (defining and displaying publishing house information), author class (defining and displaying author information), book class (defining and displaying book information), demo class (finally output in main method)

The code is as follows:

package demo05; /* * Define a publishing house class * name and address of the publishing house * / public class press {string pressname; string pressadd; public void showinfo() {system.out.println ("publishing house name:" + pressname); system.out.println ("publishing house address:" + pressadd);}

}

package demo05; /* * Define an author class, including: name, gender, major * / public class author {string authorName; int authorage; string authormajor; public void showinfo() {system. Out. Println ("author name:" + authorName); system. Out. Println ("author age:" + authorage); system. Out. Println ("author major:" + authormajor);}

}

package demo05; /* * Define a Book class, including: book name, book number, author, publisher * / public class book {string bookname; string bookid; author author; press press press; public void showinfo() {system. Out. Println ("Book Name: + bookname); system. Out. Println (" Book Number: + bookid); / / display author information author. Showinfo(); / / display publisher information press. Showinfo();}

}

package demo05; Public class demo {public static void main (string [] args) {press tsinghuapress = new press(); tsinghuapress. Pressname = "Tsinghua University Press"; tsinghuapress. Pressadd = "Beijing"; author author = new author(); author. AuthorName = "Zhang San"; author. Authorage = 36; author. Authormajor = "computer"; book javabook = new book(); javabook. Bookname = "Java programming thought" ; javaBook. bookID="1001001"; javaBook. press=tsinghuaPress; javaBook. author=author; javaBook. showInfo(); } }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>