class A{
void method1(){ //声明method1
System.out.println("method1 called")
}
void method2(){
method1() //本类的 method1 被调用
}
}
class B{
void method3(){
A a = new A() //在B类中调用A类中的 method1
a.method1()
}
}
import java.util.class Person{
// 创建Persion类
String name// 表示姓名
int age
public Person(String name,int age){
this.name=name
this.age =age
}// 表示年龄
public void tell(){
System.out.println("姓名:" + name + ";年龄:" + age)
}
}
public class test{
public static void main(String args[]){
Person per = new Person("zhang san",3) //实例化类
per.tell()//只有调用实例类的成员
}
}
-----------------------------------------------------------
打印结果 姓名:zhang san 年龄:3