What is the difference between constructor and method?
Answers were Sorted based on User's Feedback
Answer / shadow
Constructor will be automatically invoked when an object is
created whereas method has to be called explicitly. ...!
$HADOW
| Is This Answer Correct ? | 13 Yes | 3 No |
Answer / pinky
Constructor doesnt return anything. where as method may or
may not return data or value
| Is This Answer Correct ? | 6 Yes | 0 No |
Constructor must have the same as the class name,
whereas we can give any name to the method.
Constructor doesnt have any return type not even void,
whereas method must have valid return type or void if
nothing is return.
Constructor will implicitely invoke at the time of
object creation, whereas method must invoke explicitely
with the object.
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / 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 |
what is mutability?which one is mutable String or StringBuffer?and why?give examples of each which shows the mutability of each String or StringBuffer
What is java developer skills?
Can a class have multiple subclasses?
What is JIT ?
which swing component is similar to rich text box in .net/vb
what is the difference between AWT and SWING what is the advantage of using swing?
What are the main differences between the java platform and other platforms?
why we need this (1.object,2.class,3.data hiding,4.encapsulation,5.abstraction,6. polymorphism,7.inheritance)
Why local variables are stored in stack?
Why is flag used in java?
what is the difference between applet and swing and gui application in java . What we do with the collections set and list interface
2 Answers CTS, Phoenix Technologies,
what is stringtolennizer with example?