Home > Java > javaTutorial > Java basic program with expansion

Java basic program with expansion

Linda Hamilton
Release: 2024-12-30 16:03:16
Original
681 people have browsed it

Created a class as public class Library
Created a object as Library books = new Library();
Object is memory representation of class.
Most important object name should not be in capital.

How to create an object in Java? {TBD}

Java provides five ways to create an object.

Using new Keyword
Using clone() method
Using newInstance() method of the Class class
Using newInstance() method of the Constructor class
Using Deserialization
Copy after login

Code:

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");
}


}
Copy after login

Output:

Java basic program with expansion

The above is the detailed content of Java basic program with expansion. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template