DEV Community

Pavithra Saravanan
Pavithra Saravanan

Posted on

1

Java basic program with expansion

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
Enter fullscreen mode Exit fullscreen mode

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


}
Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay