• 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));
            
        }
        
        
        
        
        
    }
  • 相关阅读:
    利用线程池爬虫
    多任务协程怎么写
    利用协程多任务协程爬取前几页投诉网
    cookie的处理和代理池的建立
    bs4和xpath的用法
    怎么使用Ip代理词
    雪球网新闻标题的爬取
    爬虫学习的基础篇
    小说文本爬取
    24 张图彻底弄懂九大常见数据结构
  • 原文地址:https://www.cnblogs.com/cerofang/p/10233215.html
Copyright © 2020-2023  润新知