-
External calls
An external call is a method that calls another class in one class
Package hello2;//first defines a class
public class Book {
String name;
String author;
Double Price;
public void GetInfo () {
Output title, author, and Price as a string
System.out.println ("The title is" +name+ ", the author is" +author+ ", The Price is" +price ");
}
}
Second, apply the first class method in another class
Package Hello2;
public class Testbook {
public static void Main (string[] args)
{
Book B1=new book ();
Book B2=new book ();//Use an external call to create an object first
The operator that uses the object.
B1.name= "Java";
B1.author= "Zhangsan";
b1.price=10.45;
B1.getinfo ();////method Internal call, directly call if the class's properties and methods in another class, first create an object, B1.getinfo ();
B2.name= "ADSFAF";
B2.author= "K;l";
b2.price=100;
B2.getinfo ();
}
}
-
Internal call
Internal calls are called within a class, and can be called directly from the method name.
Package Hello2;
public class Testbook {
static String name;
static String author;
static double price;
public static void GetInfo () {
Output title, author, and Price as a string
System.out.println ("The title is" +name+ ", the author is" +author+ ", The Price is" +price ");
}
public static void Main (string[] args)//static method calls another method, another method must also be a static method, so GetInfo () is a static method.
{
Testbook b1=new Testbook ();
Testbook b2=new Testbook ();//Create Object
The operator that uses the object.
B1.name= "Java";
B1.author= "Zhangsan";
b1.price=10.45;
GetInfo ();
}}
external and internal invocation of methods such as Java Learning