View RSS Feed

Java Object

Class Methods

Rate this Entry
by , 04-26-2012 at 04:51 PM (371 Views)
Static variables as well as static methods are supported by the Java programming language. Static methods which consists of the static modifiers shall be invoked along with the class name with no need to create the class instance, as in
Java Code:
ClassName.methodName(args)
One of the most common use, for the static method, is the static file access. For instance, static method would be added to the Bicycle class for accessing static field of numberOfBicycles.
Java Code:
public static int getNumberOfBicycles() {
    return numberOfBicycles;
}
All combinations of class variables, instance and methods are not allowed:

  • Instance variables could be accessed by the instance methods, & instance methods directly.
  • Class variables could be accessed by the Instance methods & class methods directly.
  • Class variables can be accessed by class methods, and class methods directly.
  • Instance variables couldn’t be accessed by the Class methods, or instance methods directly. Object reference shall be used. The this keyworld couldn’t be used by the class methods, as instance is not present for this, to refer to.

Submit "Class Methods" to Facebook Submit "Class Methods" to Digg Submit "Class Methods" to del.icio.us Submit "Class Methods" to StumbleUpon Submit "Class Methods" to Google

Categories
Tutorial

Comments