📄 maintest.java
字号:
/*Main方法由Java虚拟机调用
*不用产生对象来调用,故是static*/
/*函数调用。。。。*/
/*
*在Java中,传参时,都是以传值的方式进行。
*
*对于基本数据类型,传递的是数据的拷贝
*对于引用类型,传递的引用的拷贝
*
*/
/*
*看是数据作为形参还是引用作为形参
*
*/
class MainTest
{
public static void change(int x,int y)
{
x=x+y;
y=x-y;
x=x-y;
}
public static void change(int[] num)
{
num[0] = num[0]+num[1];
num[1] = num[0]-num[1];
num[0] = num[0]-num[1];
}
public static void change(Point pt)
{
pt.x = pt.x + pt.y;
pt.y = pt.x - pt.y;
pt.x = pt.x - pt.y;
}
public static void main(String[] args)
{
/*
if(args.length>0)
{
for(int i=0; i<args.length;i++)
{
System.out.println(args[i]);
}
}*/
int x=3;
int y=4;
change(x,y);
System.out.println("x="+x+","+"y="+y);
int[] num=new int[]{3,4};
change(num);
System.out.println("x="+num[0]+","+"y="+num[1]);
Point pt = new Point();
pt.x = 3;
pt.y = 4;
change(pt);
System.out.println("x="+pt.x+","+"y="+pt.y);
System.out.println(pt);
/*见toString()方法*/
/*The to String method for class Object returns a string consisting
*of the name of the class of which the object is an instance,the at-sign
*character '@',and the unsigned hexadecimal representation of the hash code
*of the object.In other words,this method returns a string equal to the value of:
*
*getClass().getName() + '@'+ Integer.toHexString(hashCode())
*
*It is recommended that all subclasses override this method;
**/
}
}
class Point
{
int x,y;
public String toString()
{
return "x="+x+":"+"y="+y;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -