Java 11.01

Source: Internet
Author: User

Project


Public class project {
// Declare Variables
Int num1 = 0;
Private int num2 = 0;
// Static variables
Static int num = 0;
Int num3 = 0;
// Static constant
Public static final double Pi = 3.14;
// Constructor
Public Project (int A, int B ){
Num1 =;
Num2 = B;
}
// Method
Public int add (){
Return num1 + num2;
}
// Static method
Public static double round (){
Return 2 * pI * num;
}
}

Public class test {
Public static void main (string ARGs []) {
System. Out. println ("START ");

Int I = 0;
Double D = 0;
// Define and initialize the object
Project obj1 = new project (12, 5 );
Project obj2 = new project (15, 5 );
// Call the object Method
I = obj1.add ();
// Call static variables
Project. num = 3;
// Call the static method
D = project. Round ();

System. Out. println ("add:" + I );
System. Out. println ("circul:" + D );


// Access static variables
Obj1.num3 = 1;
Obj2.num3 = 2;
System. Out. println ("obj1.num3 =" + obj1.num3 );
System. Out. println ("obj2.num3 =" + obj2.num3 );

Project. num = 1;
Obj1.num = 2;
Obj2.num = 3;
System. Out. println ("project. num =" + project. Num );
System. Out. println ("obj1.num =" + obj1.num );
System. Out. println ("obj2.num =" + obj2.num );

}
}

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.