Monday, November 16, 2009

Basics: Class, Field, Method, Objects summarized

o A class can extend only one parent but can implement many interfaces

o The method signature comprises of two components -- the method's name and the parameters

o If a class is not provided with any constructors explicity, then the compiler automatically provides a no-argument, default constructor. This default constructor will call the no-argument constructor of the superclass. The compiler will complain in the case where a superclass is absent. If an explicit superclass does not exist, then the Object class will be the superclass implicitly.

o Varargs is used to pass an arbitrary number of values to a method. It is used when the number of arguments passed to a method of a particular datatype is unknown.

o To use Varargs, you follow the type of the last parameter by an ellipsis(3 dots ...), then a space, and the parameter name.

o Reference datatype parameters, such as objects, are also passed into methods by value. When the called-method returns, the passed reference still references the object as before calling the method. However, the values of the object's fields can be changed in the called method, if they have the proper access priviledges.

o A method returns to the code that invoked it, in 3 different occasions
   -completes all statements in the method
   -when the return keyword is encountered
   -throws an exception

o When a class name is used as a return type in a method declaration, the class of the type of returned object must be either a subclass of, or the exact class of, the return type.

No comments:

Post a Comment