Ask Experts Questions for FREE Help !
Ask
    9123456789's Avatar
    9123456789 Posts: 1, Reputation: 1
    New Member
     
    #1

    Jul 23, 2015, 11:06 PM
    Java
    public class A {
    public static void main(String[] args) {
    int a= 20;
    short b = 99;
    short[] Num = new short[10];


    Num[0] =b;


    decrease1(a);


    decrease2(Num);


    System.out.println(Num[0]);
    System.out.printf("a=%d, b=%d, Num[0]=%d",a,b,Num[0]);
    }


    static void decrease1(int num) {


    num--;


    }


    static void decrease2(short[] num) {


    num[0]--;


    }
    }




    o/p is a=20 b=99 Num[0]=98

    How num[00]=98??
    CravenMorhead's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #2

    Jul 24, 2015, 08:02 AM
    The answer here is scope and how each of the variables were passed in; pointer, reference, and value. When decrease1 is called a local copy of the variable was made and that is used internally in the function. When decrease2 is called, you're passing in an array. This is a point that points to a series of shorts. You're actually working on the array that was passed in.

    look this up in your textbook it will explain it better.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

What all topics comes under advance java?what is framework how it is related to java? [ 0 Answers ]

I want to know about the topics related to advance java?and how the framework likke struts and hibernate realted to each other?what are there uses?

I am new to java GUI and multiple classes, I have knowledge of core java. I have [ 0 Answers ]

Sir, I am new to java GUI and multiple classes, I have knowledge of core java. I have to call a rest client from my net beans project give values to it and receive it's output in the same project. Please suggest me what I need to study and what to do.

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...

Ask for java help [ 0 Answers ]

Can somebody please help me with the code for this question? I don't even know where to begin :( Write the code for the following methods in the newDate class: Public boolean validDate (int day, int month, int year) The month can only be in the range 1-12 and a month must have the correct ...

Ask for help in java [ 0 Answers ]

Hi guys can you help me on java. I want to add some data on a jcombobox from mysql database. I created 2 comboboxes. After I retrieve the necessary data from the database it will automatically fill up the first combobox. And then in the first combobox the user chooses the data he wants...


View more questions Search