Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Java Methods

A method is a group of instructions that is given a name and can be called up at any point in a program simply by quoting that name. For instance, we met an instruction in the last lesson that draws a straight line on the screen. We could use this instruction three times to draw a simple triangle.
  1. Methods define actions that a class's objects (or instances) can do.
  2. A method has a declaration part and a body.
  3. The declaration part consists of a return value, the method name, and a list of arguments.
  4. The body contains code that perform the action.
  5. The return type of a method can be a primitive, an object, or void.
  6. The return type void means that the method returns nothing.
  7. The declaration part of a method is also called the signature of the method.

Exmaple:
public class MainClass {

  double getSalary() {
    return 0.0;

  }
}

Passing Objects to a Method
class Sphere {
  double radius; // Radius of a sphere
  Sphere() {
  }
  // Class constructor
  Sphere(double theRadius) {
    radius = theRadius; // Set the radius
  }
}

public class MainClass {
  public static void main(String[] arg){
    Sphere sp = new Sphere();
    
    aMethod(sp);
  }

  
  private static void aMethod(Sphere sp){
    System.out.println(sp);
  }
}

Returning From a Method
public class MainClass {
  private int aField;

  public void aMethod() {

  }
  public double volume() {
    return 50;
  }
  
}

 
     
   
Java Language Tutorial
 
  What is JAVA
What is JAVA
  Java an Object Oriented Language
Java an Object Oriented Language
  Java Keywords
Java Keywords
  Data Types
Data Types
  Java Operators
Java Operators
  Control Structure
Control Structure
  Arrays
Arrays
  Java Classes
Java Classes
  Java Constructors
Java Constructors
  Java Methods
Java Methods
  Java Method Overloading
Java Method Overloading
  Java Method Overriding
Java Method Overriding
  Java Nested Classes
Java Nested Classes
  Inheritance in Java
Inheritance in Java
  Interfaces in Java
Interfaces in Java
  Polymorphism in Java
Polymorphism in Java
  Exception Handling in Java
Exception Handling in Java
  Catching Exceptions
Catching Exceptions
  Embedding information in an exception object
Embedding information in an exception object
  The throws clause
The throws clause
  Checked and unchecked exceptions
Checked and unchecked exceptions
  The finally clause
The finally clause
  Applets in Java
Applets in Java
  Running an Applet
Running an Applet
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download PHP 5 Power Programming  Ebook PHP 5 Power Programming
   
Download Electromagnetic Waves and Antennas  Ebook Electromagnetic Waves and Antennas
   
Download Niche Marketing Research In Plain English Ebook Niche Marketing Research In Plain English
   
Download Capability-Based Computer Systems  Ebook Capability-Based Computer Systems
   
Download Computer Organization and Design Fundamentals  Ebook Computer Organization and Design Fundamentals
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz