Home >Java >javaTutorial >object & class creation

object & class creation

Patricia Arquette
Patricia ArquetteOriginal
2025-01-05 08:49:40770browse

Object creation:(Behavior)

Example:
public class Bank
{

public static void main(String[] args)
{
Bank manager = new Bank(); //Object Creation
//new allocates memory - Instance - Instantiation
manager.openAccount(); //Method Calling Statement
Bank cashier = new Bank();
cashier.deposit();

}

public void deposit() //Method Signature
{
//Method Definition / Body
System.out.println("Deposit amount in our Bank");
}

public void openAccount() //Method Signature
{
//Method Definition / Body
System.out.println("Opening Account in our Bank");
}

}

Output:
Opening account in our bank
deposit amount in our bank

object & class creation

Task:1
public class Mobile // create a class
{
public static void main (String[] args)
{
Mobile whatsapp = new Mobile();//instantiation
//new allocates memory
whatsapp.chat();//method calling statement
Mobile youtupe = new Mobile();
youtupe.watch_movie();
}

public void chat()//method signature
{
// method definition/body
System.out.println("sent a message in a group");
}
public void watch_movie()
{
System.out.println("i am watching movies in youtupe");
}
}

Output:
sent a message in a group
i am watching movies in youtupe

object & class creation

Task:2
public class Instagram
{
public static void main(String[] args)
{
Instagram message = new Instagram();
message.receive();
}
public void receive()
{
System.out.println(" I receive a message from my friend ");
}
}

Output:
I receive a message from my friend

object & class creation

The above is the detailed content of object & class creation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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