View RSS Feed

Java Object

Object-oriented programming in Java.

  1. Passing Reference Data Type Arguments

    by , 04-26-2012 at 05:23 PM
    Reference data type parameters also get passed by the value into methods. It shows that by returning methods, same objects are referred by the passed in reference. But, the objectís field value might get changed in case there is a proper access level.

    Let us take a method into consideration present in arbitrary class, which will be moving the Circle objects.
    Java Code:
    public void moveCircle(Circle circle, int deltaX, int deltaY) {
        // code to move origin of
    ...
  2. Passing Primitive Data Type Arguments

    by , 04-26-2012 at 05:21 PM
    Primitive arguments for example, a double or an int, get passed by value into methods. This shows that changes to parameter values are present just in the methodís scope. When methods are returned it means that parameters have been gone & all alterations have been lost. For example:
    Java Code:
    public class PassPrimitiveByValue {
    
        public static void main(String[] args) {
               
            int x = 3;
               
            // invoke passMethod()
    ...