User Tools

Site Tools


java:member_initialization

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
java:member_initialization [2022/02/24 05:34] – [Αρχικοποίηση των μελών της κλάσης] gthanosjava:member_initialization [2022/02/24 12:39] (current) – external edit 127.0.0.1
Line 168: Line 168:
   int getArea() {   int getArea() {
        return width * height;        return width * height;
-  } 
-    
-  // Move rectangle origin by x,y 
-  void move(int dx, int dy) { 
-    origin.setX( origin.getX() + dx ); 
-    origin.setY( origin.getY() + dy ); 
   }   }
      
-  String toString(String objName) { +  String description(String objName) { 
-      return "["+objName+"." + id + "Width: " + width + ", Height: " + height + ", Origin: " + origin;+      return "["+objName+"] (id: "+ id +"Width: " + width + ", Height: " + height;
   }   }
      
-  static void main(String []args) {+  public static void main(String []args) {
     System.out.println("-------------------------------");     System.out.println("-------------------------------");
     Point p = new Point(10,20);     Point p = new Point(10,20);
 +    
     Rectangle rectOne = new Rectangle(30,40, p);     Rectangle rectOne = new Rectangle(30,40, p);
-    System.out.println(rectOne.toString("rectOne")); 
     System.out.println("-------------------------------");     System.out.println("-------------------------------");
 +    System.out.println(rectOne.description("rectOne"));
     System.out.println("Number of Rectangles: " + getNumberOfRectangles() );     System.out.println("Number of Rectangles: " + getNumberOfRectangles() );
   }   }
Line 200: Line 195:
 initialize objectId in block, id: 100 initialize objectId in block, id: 100
 Initialized object id in constructor, id:1 Initialized object id in constructor, id:1
-[rectOne.1] Width: 30, Height: 40, Origin: [Point xPos:10, yPos:20] 
 ------------------------------- -------------------------------
 +[rectOne] (id: 1) Width: 30, Height: 40
 Number of Rectangles: 1 Number of Rectangles: 1
 </code> </code>
Line 214: Line 209:
 </WRAP> </WRAP>
  
-|Προηγούμενο: [[:java:static_keyword | Στατικές μεταβλητές και μέθοδοι ]] | [[ :toc | Περιεχόμενα ]] | Επόμενο: [[ :java:toString Η μέθοδος toString ]]| +|Προηγούμενο: [[:java:static_keyword | Στατικές μεταβλητές και μέθοδοι ]] | [[ :toc | Περιεχόμενα ]] | Επόμενο: [[ :java:string Αλφαριθμητικά ]]|
- +
- +
- +
  
java/member_initialization.1645680880.txt.gz · Last modified: 2022/02/24 05:34 by gthanos