how can we differentiate b/w a constructor and a method?
how can we differentiate b/w a constructor and a method?
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Khurram
31 October 2018, 18:09
constructors are called implicitly when an object is instantiated, methods are called explicitly on objects
constructors do not have return types, methods have a return type
+1
kapil
31 October 2018, 18:08solution
constructor>>>1. name is same as class name
2. no return type
3. used to initialize instance variables
e.g.
private class Car{ // class
}
public Car(){ // constructor
}
public int car(){ // method
}
+3