Use of simple classes, objects, and methods

Source: Internet
Author: User
Package  Test;  Class  Point {  Int  X;  Int  Y; string name = "No Name" ; Point () {x = 0 ; Y = 0 ;} Point (  Int X, Int  Y, string name ){  This . X = X;  This . Y = Y;  This . Name = Name ;}  Void Move ( Int X, Int  Y ){  This . X = X;  This . Y = Y ;}  Void Newname (string name ){  This . Name = Name ;}  Int Equal ( Int X, Int  Y ){  Return   This . X = x? ( This . Y = y? 1:0): 0 ;}  Void  Getx () {system. Out. println (x );}  Void Gety () {system. Out. println (y );}  Void  Getname () {system. Out. println (name );}}  Public   Class  Main {  Public   Static   Void  Main (string ARGs []) {point = New  Point (); A. getx (); A. Gety (); A. getname (); A. Move ( 20, 20 ); A. newname ( "Gxm"); A. getx (); A. Gety (); A. getname ();  If (A. Equal (20, 20) = 1 ) System. Out. println ( "OK" );  Else  System. Out. println ( "No" );  If (A. Equal (20, 21) = 1 ) System. Out. println ( "OK" );  Else  System. Out. println ( "No");}} 

Output:

0
0
No name
20
20
Gxm
OK
No

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.