操作方法和调用方法 public class AlllnMain public static void main(string argsI int int1=42 int int2=24 System. out. println(int 1+int2); 这种方法是简洁的,但是它: 在较大的应用程序中是不现实的 >没有使用面向对象的思想 还有其它缺点
操作方法和调用方法 • public class AllInMain { public static void main(String args[]) { int int1=42; int int2=24; System.out.println(int1+int2); } } • 这种方法是简洁的,但是它: ➢在较大的应用程序中是不现实的 ➢没有使用面向对象的思想 ➢还有其它缺点
public class One public static void main (String args[1) 调用方法 Two twoRef new Two ( twoRef. workerMethod(); I public class Tw public void workerMethod () 操作方法 int intl =42: int int2 241 System. out. println(intl int2
操作方法和调用方法 用方运让对象用它的一个方法来为你做某件事情。 丶≥调用方法除调用操作方法外,通常还有普通的方法操作 对象的用方法可以为您: 获得输入信息 返回一条信息 查看结果; BoxDemo3java
操作方法和调用方法 • 调用方法让对象用它的一个方法来为你做某件事情。 ➢调用方法除调用操作方法外,通常还有普通的方法操作 • 对象的调用方法可以为您: ➢获得输入信息 ➢返回一条信息 查看结果:BoxDemo3.java
调用方法与操作方法的独立存在: 1 public class callingclase 2345678 main is the calling method public static void main(String angs[]) // Thie line creates an object of the class with worker methode co specify which object a methods should run, in lines 13-14 10 Workerclass workerobject new workerclass ()i 11 / the next two lines use the object to / call worker methods method1 and method2 13 workerobject worker1()7 14 workercbject. worker( 15 16 1 // this class contains the worker methods for this example 2 public class Workerclass 3456789 // code block for worker public void workorl( int工D-44559; System. out.println("The ID is"+ID)i 10 7 code block for worker 12 public void workor2( 11 13 float price -29.99F: 14 System. out.println("The price is price); 15 16
调用方法与操作方法的独立存在:
声明方法 ·操作方法和调用方法具有相同的语法结构 ·在所有示例中并不包含全部可能的方法 矿方法的定义 [修饰符]返回类型方法名称([参数表]) //方法体 查看结果: BoXDemo4iava
声明方法 • 操作方法和调用方法具有相同的语法结构 • 在所有示例中并不包含全部可能的方法 查看结果:BoxDemo4.java