Classes and objects.

Source: Internet
Author: User

Package Com.demo;

public class Student {

String name;

char sex;

int age;

}

Package Com.demo;

public class Studenttest {

public static void Main (string[] args) {

Student wangstu=new Student ();

Wangstu.name= "Wang Hongtao";
wangstu.age=18;

wangstu.sex= ' Women ';

Wangstu.showstudent ();

}

}

Package Com.demo;

Import Java.util.Scanner;

public class Persontest {

public static void Main (string[] args) {

Person Person=new person ();

Person.show ();

}

}

Protected: Protected
Private: Private
Public: Common
Access level

Package Com.demo;

Import Java.util.Scanner;

public class Person {

public String name;

public int age;

/**

* Used to loop receive user input and then determine age

*/

/**

* If classes and attributes have methods that do not add access modifiers, then the default is?

* Default is Public

*/

public void Show () {

Scanner input=new Scanner (system.in);

System.out.println ("Please enter Name:");

Name=input.next ();

1. Cycle

while (!name.equals ("n")) {

System.out.println ("Please enter Age:");

Age=input.nextint ();

2. Judging

if (age>=18&&age<=60) {

System.out.println ("tickets 20 Yuan");

}else{

System.out.println ("Ticket free");

}

System.out.println ("Please enter Name:");

Name=input.next ();

}

SYSTEM.OUT.PRINTLN ("The program is over!" ");

}

}

Classes and objects.

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.