JAVA 面向对象

盖码范

关注

阅读 59

2022-04-04

package com.OOP;

public class Demo01 {
    public static void main(String[] args) {
        //面向对象编程的本质:以类的方式组织代码,以对象的组织(封装)数据。
        //三大特征:封装 继承 多态
        System.out.println(max(20,30));
        sayHello();//调用静态方法

        System.out.println("=======================================");

        Demo01 demo01=new Demo01();//调用非静态方法
        demo01.max1(20,30);//调用非静态方法
        System.out.println(demo01.max1(20,30));
    }

    public static String sayHello(){
        System.out.println("Hello World!");
        return "Hello World!";
    }
    //静态方法 max
    public static int max(int a,int b){
        return a>b ? a: b;
    }
    //非静态方法
    public int max1(int a,int b){
        return a>b ? a: b;
    }
}

精彩评论(0)

0 0 举报