Class in Java 2

Java-Tutorial.org

Classes in Java

class Punkt // Declaration of the class Punkt {/ * The class body contains data fields (attributes) * /}

 


 

class point // declaration of the class point {int x_coordinate; / * x position of our point * / int y_coordinate; / * y position of our point * /} class point // declaration of the class point {int x_coordinate; / * x- Position of our point * / int y_coordinate; / * y-position of our point * / // start of the method methodepublicvoid methode () {int local_variable; / * locally declared variable can only be used within the method * /} // end of the method method }

 

Attributes can themselves also be complex data types. To make this clear, let's create the Line class:

class line // Declaration of the class point {point point_one; // gives the first point of the line at point point_two; // specifies the second point of the line}

We are therefore creating two attributes that are based on our Point class as the data type.

classvariablesArten {int x; // instance variablesestaticint y; // class variable // method start void method () {int z = 0; // local variable} // method end}

 


 

class example {int variable1;} class example2 {int variable_1;}

 

class example3 {example ex;}

 


 

class example4 {int variable_1; // start of method methodepublicvoid method (int val) {variable_1 = val;} // end of method method} class example5 {int variable_1; // start of method methodepublicvoid method (int val) {int variable_1 = val;} // end of method method}

 

class Example6 {// start of method methode_1publicvoid methode_1 (int val) {int variable_1 = val;} // end of method methode_1 // start of method methode_2publicvoid methode_2 (int val) {int variable_1 = val;} // end of method method_2}

 

class example4 {int variable_1; // start of method methodepublicvoid method (int val) {this.variable_1 = val;} // end of method method}


 

class example7 {int variable_1 = 0; // Start of method methode_1publicint methode_1 (int val) {variable_1 = val; int variable_1 = val; this.variable_1 + = val; returnthis.variable_1;} ​​// End of method methode_1 // Start of method methode_2publicint methode_2 (int val) { int variable_1 = val; return variable_1;} ​​// end of method methode_2}