DEV Community

vimala jeyakumar
vimala jeyakumar

Posted on

object & class creation

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

Image description

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

Image description

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

Image description

Top comments (0)