Practice defining class student classes

The code is as follows: (use member variables defined in other classes in one class)

package demo04; /* * Define class classes, including class name, address and other information, and methods to display class information * / public class Banji {string banjiname; string banjiadd; public void showinfo() {system.out.println ("class name: + banjiname); system.out.println (" class address: + banjiadd);}

}

package demo04; /* * Define the student class. The student has at least the class member variable, which displays all the information of the student * / public class student {string stuid; string stuname; int score; Banji stubanji; / / student class public void showinfo() {system. Out. Println ("student ID: + stuid); system. Out. Println (" grade: + score); stubanji. Showinfo();}

}

package demo04; Public class demo {public static void main (string [] args) {Banji java399 = new banji(); java399. Banjiname = "Java class"; java399. Banjiadd = "2-1"; student stu1 = new student(); stu1. Stuid = "20180001"; stu1. Score = 80; / / specify the class of students stu1. Stubanji = java399; / / display student information stu1. Showinfo(); student stu2 = new student()) ; stu2. stuBanji=java399; stu2. showInfo(); } }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>