zoukankan      html  css  js  c++  java
  • java方法的调用

    各种方法的调用实例

    package cn.edu.fhj.day004;
    
    public class FunctionDemo {
    //    定义全局的变量
        public int a = 3;
        public int b = 8;
        
    //    定义一个没有返回值的函数
        public void sayHello() {
            System.out.println("kkkhhh");
        }
        
    //    无参数,有返回值
        public int  getSelfSum() {
            return a+b;
        }
        
    //    有参,无返回值
        public void getName(String name ){
            System.out.println("kkk" + name);
        };
        
    //    有参,有返回值,且是静态
        public static int getSumIsStatic(int number1 , int number2) {
            return number1+number2;
        }
        
        
    //    参数,有返回值,非静态
        public int getSumNoStatic(int x) {
            return this.a + this.b + x;
        }
        
        
        
    }

    调用

    package cn.edu.fhj.day004;
    
    public class FunctionDemoTest {
    //    public static void main(String[] args) {
    //        FunctionDemo fun = new FunctionDemo();
    //        fun.sayHello();
    //    }
        
        
    //    调用定义的有返回值的函数
    //    public static void main(String[] args) {
    //        FunctionDemo fun = new FunctionDemo();
    //        
    //        System.out.println(fun.getSelfSum());
    //    }
        
        
    //    调用有参,无返回值
    //    public static void main(String[] args) {
    //        FunctionDemo fun = new FunctionDemo();
    //        fun.getName("fhj");
    //    }
        
        
    //    调用有参,有返回值
        public static void main(String[] args) {
            FunctionDemo fun = new FunctionDemo();
            System.out.println(fun.getSumNoStatic(3));
            
        }
        
        
        
        
        
    }
  • 相关阅读:
    迁移式学习
    VMware Workstation 16激活码
    OpenStack安装部署
    git码云操作
    vs 2019 正则替换
    linux中Redis单机安装
    ASP.NET/C#执行数据库过程函数带RETURN的项目接收。
    IDEA配置部属Tomcat
    Java集合之HashMap源码分析(put()方法)
    反编译一款APP然后重新打包(Windows环境)
  • 原文地址:https://www.cnblogs.com/cerofang/p/10233215.html
Copyright © 2011-2022 走看看