Difference between a constructor and a method November 19, 2006
Posted by Allu in JAVA.trackback
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.
the terminology is quite easy to understand.i make sure to approach this site whenever i come across a problem.
i want to know about interfaces. how interfaces are different from abstract classes? please explain me
thank you
abstract class may define some method and may contain all method abstract but interface can not define any method, it only contain abstract method.
Interfaces enable you to implement multiple inheritance but oly one class can be inherited by abstract class.
Interface consists of methods only whereas abstract class contains attributes ad methods.
Abstract class is used in the same package whereas interfaces can be realised across multiple packages.
differences are all very good, but what is the similiarity?
though the difference is good y cant we use only constructors instead of methods .which will be very easy for us to handle
What is the use of bin and lib in jdk?
Bin contains all tools such as javac,appletviewer,awt tool etc where as lib contains API and all packages
yes now i understand this difference
Interface:
If u declare one class as a interface , inside the interface we should give the signature for the method… no need to give the definition.
If u extend the interface we should give the definition for the method.
Abstract:
In ur extended sub class u forgot to give the definition for the method.then u should eclare ur superclass as a abstrasct class…..
what is the properaties of using keyword ( this) in the cinstractor
Default access specifier for Constructor is public and method is private. Constructor should have same name as Class name. Constructor can be overloaded like methods.
can any 1 help in java programs???
thanks
best bt can’t given any exp..for this
Abstract class- it contains concrete and abstract methods.if there is 1 number of method is abstract then the class should be defined as a abstract class. else if there is no any abstract method then its not mandatory to defined class as a abstract class
Interface-by default all the methods public or abstract .there is no need to define the method abstract. and in the case of interface we can implement more than 1 class
thanks for all this