class Demo{ public int sum(int a,int b){ return a+b; } } class Student1{ public void show(){ System.out.println("I love learning"); } } class StudentDemo{ //If you see that the formal parameter of a method is a class type (reference type), what is needed here is the class object public void method(Student1 s){ s.show(); } } public class ArrayTest { public static void main(String[] args){ Demo d =new Demo(); StudentDemo sd = new StudentDemo(); //create student object Student1 s =new Student1(); sd.method(s);//Give the address of s here } }
object passing of class
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325936229&siteId=291194637
Recommended
Ranking