1.复习类、对象
如何定义类
如何生成方法?
如何生成对象?
如何调用方法?
如何定义属性/成员变量?
-
方法传递参数
public class ParamTest { public static void main(String[] args) { Person person = new Person(); person.change(person); int age = person.age; System.out.println(age); System.out.println("---------------"); int i = 10; person.change2(i); System.out.println(i); } } class Person { int age = 20; public void change(Person person) { person = new Person(); person.age = 30; } public void change2(int age) { age = 40; } }
3.构造方法
public class Test
{
public static void main(String[] args)
{
Person person = new Person(50);
System.out.println(person.age);
}
}
class Person
{
int age;
public Person(int i)
{
age = i;
}
}