创建一个类作为公共类库
创建一个对象作为 Library books = new Library();
对象是类的内存表示。
最重要的对象名称不应大写。
如何在Java中创建对象? {待定}
Java 提供了五种创建对象的方法。
Using new Keyword Using clone() method Using newInstance() method of the Class class Using newInstance() method of the Constructor class Using Deserialization
代码:
public class Library { public static void main(String[] args) { Library books = new Library(); //Object Creation //new allocates memory - Instance - Instantiation books.fiction(); //Method Calling Statement Library librarian = new Library(); librarian.lending_books(); } public void fiction() //Method Signature { //Method Definition / Body System.out.println("Book Name:Fiction books"); } public void lending_books() //Method Signature { //Method Definition / Body System.out.println("Librarian:Successfully lended the books"); } }
输出:
以上是Java基本程序及扩展的详细内容。更多信息请关注PHP中文网其他相关文章!