1.面向對象
|-OOA面向對象的分析
|-OOD面向對象設計
|-OOP面向對象程序
2.對象的產生
對象聲明:類名稱 對象名稱=null;//在棧中開闢空間
對象實例化:對象名稱=new 類名稱();//在堆中開闢空間
在堆中其實放的是對象的各個屬性,因為對象中只能依靠屬性不同來區分。
3.如果只聲明對象不實例化對象就會報空指針異常
4.而全部的方法都保存在全局代碼中
5.一個棧內存只能指向一個堆內存的。
6.一個類至少有一個構造方法,如果沒寫,系統會生成一個無參構造方法,構造方法在new的時候實例化。構造方法是無返回值的,但可以用return 退出構造方法
class Student{
private String name ;
private int age ;
private float english ;
private float computer ;
private float math ;
public Student(){}
public Student(String n,int a,float e,float c,float m){
this.setName(n) ;
this.setAge(a) ;
this.setEnglish(e) ;
this.setComputer(c) ;
this.setMath(m) ;
}
public float sum(){
return english + computer + math ;
}
public float avg(){
return this.sum() / 3 ;
}
public float max(){
float max = computer>math?computer:math ;
max = max>english?max:english ;
return max ;
}
public float min(){
float min = computer
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15127599/viewspace-664342/
,如需转载,请注明出处,否则将追究法律责任。