Java class and Object basics Exercise 1, student information, 2 ways

Source: Internet
Author: User

The first method; object initialization.

 PackageCom.hanqi;Importjava.lang.*; Public classstudent{intXuehao;    String name; intAge ; Student (intXuehao,string name,intAge ) {         This. xuehao=Xuehao;  This. name=name;  This. age=Age ; }    voidoutput () {System.out.println ("School Number:" +xuehao+ "" + "Name:" +name+ "" + "Age:" +Age ); }         Public Static voidMain (string[] args) {student S1=NewStudent (44, "Xiaoming", 21);    S1.output (); }}

In the second method, you create multiple objects of the student class in the main method of the Master class, using these objects to measure

 PackageCom.hanqi; Public classTextclass { Public Static voidMain (string[] args) {student S1=NewStudent (1, "Xiaoming", 21);         S1.output (); Student S2=NewStudent (2, "Little Red", 22);        S2.output (); Student S3=NewStudent (3, "Xiao Wen", 23);         S3.output (); Student S4=NewStudent (4, "Little Fang", 24);    S4.output (); }}

Java class and Object basics Exercise 1, student information, 2 ways

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.