Analysis of method value in Java by small knowledge

Source: Internet
Author: User

  • 1.only values are passed between Java language parameters, including calls by value and by reference. A method can modify the value of the variable that corresponds to the passed reference, and cannot modify the value of the variable that corresponds to the pass-through value invocation. Call by value: including the eight basic data types are called by value. When you pass a value, that means that the method gets one of all parameter valuescopy. Invoke by reference: Array, object. When passing a value, a copy of the referenced address is passed, but all points to the same object. 2.string is immutable class (final and immutable)Let us give you an example:
    public class example{string Str=new string ("good");    Char[]ch={' A ', ' B ', ' C '};        public static void Main (String args[]) {Example ex=new Example ();        Ex.change (ex.str,ex.ch);        System.out.print (ex.str+ "and");    System.out.print (ex.ch);        } public void Change (String Str,char ch[]) {//reference type variable, passed by address, belongs to reference pass.        str= "Test OK";    Ch[0]= ' G '; }}

      

    Therefore, the question should be selected B

Analysis of method value in Java by small knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.