zoukankan      html  css  js  c++  java
  • java函数

    1)参数:

    参数有按值传递的。

    当函数参数是原始类型时,,不能改变参数的值。

    当参数类型是引用类型时,可以通过调用此对象的方法来改变参数的值。如下:

    参数是原始数据类型:(不会改变参数值)

    public void getclor(int red,int blue,int green)
    {
    red=redvalue;
    green=greenvalue;
    blue=bluevalue;
    }

    参数是引用数据类型:(可以通过调用对象的方法来改变值)

    public void getclor(color temp)
    {
    temp.red=redvalue;
    temp.green=greenvalue;
    temp.blue=bluevalue;
    }

    2)返回值:

    当返回值是一个类时,返回的类必须是本类或者本类的子类。其他无要求。

    3)this:

    在方法或者构造器中,this所指的是当前对象,也就是该方法或者构造器的所属对象。

    使用this这么做的原因是方法或者构造器的参数隐藏了对象的成员变量。

    public void getclor(int red,int blue,int green)
    {
    this.red=redvalue;
    this.green=greenvalue;
    this.blue=bluevalue;
    }

    在构造器中可以通过this来调用本类中的另一个构造器,这个称为显示调用。

    public class rectangle{

    int x,y;

    int widtd,height;

    public rectangle()
    {
    this(0,0,0,0);
    }

    public rectangle(int x,int y)
    {
    this(x,y,0,0);
    }

    public rectangle(int x,int y,int width,int height)
    {
    this.x=x;
    this.y=y;
    this.widtd=width;
    this.height=height;
    }
    }

  • 相关阅读:
    STM8S PWM输出停止后 IO口电平输出
    STM8 输出比较极性
    无法打开包括文件: “corecrt.h”: No such file or directory
    VC++深入详解学习笔记
    x86系列微处理器中8种描述符表https://blog.csdn.net/u014162133/article/details/46573873
    计算机目录
    windbg双机调试
    二叉树
    list
    vector
  • 原文地址:https://www.cnblogs.com/cs1003/p/3405923.html
Copyright © 2011-2022 走看看