What is the difference between constructor and method?

Answer Posted / rattaiah addanki

methods:
modifiers_list Return_type Method_name(Parameter_list)
public void withdraw(int accno)
{
business logic
}

1) method is used to provide the business logic of the project
2) the methods are executed whenever wee are calling that
methods.
3) every method having return type.

Constructors:-
Modifiers_list Constructor_name(parameters)
ex:- public Test(int i)


1) where as constructors are used to create object.
2) the constructor is executed then only object is created.
3) at the time of object creation the constructors are
executed no need of calling.
4) if we want to execute any code at time of the object
creation then we should go for constructors concept.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between postfix and prefix operators in java.

643


What is t in generics in java?

561


What is the char data type?

523


How do you achieve singleton?

531


Which variables are stored in heap?

541






How do you allocate memory to object?

516


How do you delete a list in java?

534


Can a static method be overridden in java?

557


Where pragma is used?

598


Give a practical example of singleton class usage?

593


In how many ways we can do exception handling in java?

577


What is files manifesting?

1727


What does a void function return?

551


What does isempty () do in java?

601


Explain what pure virtual function is?

598