La programmation met en œuvre unBookCatégorie,Contienttitle,author,price,publisherQuatre variables membres,Parmi euxtitleEtauthorUniquement parget()Accès aux méthodes,priceEtpublisherPeut passerset()Etget()Accès à,RéécritureBookMéthode de construction de la classe,La méthode passe àtitleEtauthorDeux paramètres.
C'est simple.,Oui.get、setEt la méthode de construction————Quelque chose de fondamental à comprendre(privateVariable de,Le monde extérieur n'est pas libre d'accès)
public class Book { private String title; private String author; private Double price; private String publisher; public Book(String title, String author) { this.title = title; this.author = author; } public String getTitle() { return title; } public String getAuthor() { return author; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } public String getPublisher() { return publisher; } public void setPublisher(String publisher) { this.publisher = publisher; }}
public class Book { private String title; private String author; private double price; private String publisher; public Book(String title, String author) { this.title = title; this.author = author; } public String getTitle() { return title; } public String getAuthor() { return author; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getPublisher() { return publisher; } public void setPublisher(String publisher) { this.publisher = publisher; } }
Ce test est publishSuivez - moi.privateSignification de,J'espère que ça t'aidera