面向对象与方法
面向对象是分类模式思想

什么是面向对象 oop
面向对象编程的本质是:以类的方式组织代码,以对象的组织(封装)数据!
三大特性
封装
继承
多态

方法的加深理解

import java.util.Arrays;
//类
public class Demo1 {
//方法
public static void main(String[] args) {
}
/*
修饰符 返回值类型 方法名(...){
方法体
return 返回值;
}
*/
public String sayHello(){
return "hello,world";
}
public int max (int a,int b){
return a>b ? a:b; //三元运算符!应用比较多
}
}
方法的调用
public class Demo1 {
//方法
public static void main(String[] args) {
//静态方法 Static ; 可以直接调用
Student.say();
//非静态方法 :非静态方法调用需要实例化对象,即new一个对象
Student student = new Student();
student.eat();
}
}

浙公网安备 33010602011771号