第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

怎樣把一個類的方法全寫到另一個類中

怎樣把一個類的方法全寫到另一個類中

冉冉說 2019-03-22 13:15:04
package exercisepack;public class Student{public int num;public String name;public int score;public Student next;public Student(int nu,String na,int sc,Student ne){this.num=nu;this.name=na;this.score=sc;this.next=ne;}public Student(){}}這是我定義的一個學生類,然后我在同一個包下創(chuàng)建一個查找類來實現查找功能。標題上已經說了,所以這里就是要把學生里的各種方法寫到查找類里。package exercisepack;import exercisepack.Student;public class Search{static Student stu;static int length=1;static void setNext(Student t){stu=t;}static Student getNext(){return stu;}static void find(int nu){for(int i=1;i<10;i++){Student st=stu;st=getNext();if(nu==st.num){System.out.println("學號為"+nu+"的學生成績?yōu)椋?quot;+st.score);}}}public static void main(String[] args) {// TODO Auto-generated method stubStudent stu=new Student(1,"stu1",(int)(Math.random()*100),null);for(int i=1;i<10;i++){setNext(new Student(i+1,"stu"+(i+1),(int)(Math.random()*100),stu));stu=getNext();length++;}find(1);System.out.println("長度為"+length);}}我是這樣寫的,可是我的查找函數死活都不行,我調的時候發(fā)現是for(int i=1;i<10;i++){Student st=stu;st=getNext();if(nu==st.num){System.out.println("學號為"+nu+"的學生成績?yōu)椋?quot;+st.score);}}這里的問題,這里的st.num始終都沒有變過,一直都是第10個學頭疼生的信息,我看了整個stu對象,確實是存儲了10個學生的信息。這可讓我頭疼啊,請高手們出謀劃策啊,,,謝謝了!
查看完整描述

4 回答

?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

用你的查找類繼承你的學生類就可以了。
public class Search extends Student {

………………
}


查看完整回答
反對 回復 2019-04-26
  • 4 回答
  • 0 關注
  • 697 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號