⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invocationcounter.java

📁 java编程代码
💻 JAVA
字号:

public class InvocationCounter
{
    private static int numberOfInvocations = 0;

    public void demoMethod( )
    {
        numberOfInvocations++;
        //In a real example, more code would go here.
    }
   
    public void outPutCount( )
    {
        numberOfInvocations++;
        System.out.println("Number of invocations so far = "
                                      + numberOfInvocations);
    }

    public static int numberSoFar( )
    {
        numberOfInvocations++;
        return numberOfInvocations;
    }

    public static void main(String[] args)
    {
        int i;
        InvocationCounter object1 = new InvocationCounter( );
        for (i = 1; i <= 5 ; i++)
           object1.demoMethod( );
        object1.outPutCount( );

        InvocationCounter object2 = new InvocationCounter( );
        for (i = 1; i <= 5 ; i++)
        {
           object2.demoMethod( );
           object2.outPutCount( );
        }

        System.out.println("Total number of invocations = "
                           + numberSoFar( ));
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -