java數(shù)組刪除指定元素 怎么new一個(gè)對(duì)象數(shù)組java?
怎么new一個(gè)對(duì)象數(shù)組java?首先,我們需要?jiǎng)?chuàng)建一個(gè)類:class student{string name double score string num student(string n,doub
怎么new一個(gè)對(duì)象數(shù)組java?
首先,我們需要?jiǎng)?chuàng)建一個(gè)類:
class student{string name double score string num student(string n,double s,string m){name=n,s=score num=m}public static void printinfo(){系統(tǒng)輸出打?。╪um“,”name“,”score)}}下一步,我們?yōu)檫@個(gè)類創(chuàng)建一個(gè)數(shù)組://1 student stu[]ltspan style=“白色-空間:預(yù)“></span>//聲明數(shù)組。stu=新學(xué)生[3]<span style=“白色-空間:預(yù)“></span>//創(chuàng)建數(shù)組。這是一個(gè)創(chuàng)建的引用數(shù)組。每個(gè)引用都沒有確切的地址。對(duì)于(int i=0i<3i){<span style=“白色-空間:預(yù)></span>//為數(shù)組創(chuàng)建一個(gè)對(duì)象,即將創(chuàng)建的引用與確切的地址相關(guān)聯(lián)。stu[i]=new Student()}//2 Student stu[]=new Student[3]for(int i=0i<3i){stu[i]=new Student()}//3 Student stu[]=new Student{new Student(sjl,87,01),new Student(ljs,98,02),new Student(LLS,92,03)}
因?yàn)槟贐的構(gòu)造函數(shù)中創(chuàng)建了一個(gè)新的數(shù)組對(duì)象,如果要使用父類A中的數(shù)組,請(qǐng)執(zhí)行以下操作: