Computer Science, asked by ayush020702, 11 months ago

what is the difference between constructor and function

Answers

Answered by dhanrajaditya01
1

if name of a function is same as class name then it is known as Constructor and if name of a function is not same as class name then it is known as method.


Example:

public class Customer


{

private int account; //data member


private String name;


private float amount;


Customer() //constructor (doesn't has return type)


{


}


public void deposit(int amount) //method (has return type)


{

this.amount+=amount;


}


}

//If you got your answer then give a good rating

Attachments:
Similar questions