Java Basics: create class object

Posted by user1767853 on Stack Overflow See other posts from Stack Overflow or by user1767853
Published on 2012-10-25T04:45:49Z Indexed on 2012/10/25 5:00 UTC
Read the original article Hit count: 77

Filed under:
|

In C++:

class Rectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area () {return (x*y);}
};

int main () {
  Rectangle rect;
  rect.set_values (3,4);
}

In Java:

class Rectangle {
    int x, y;
    void set_values (int x,int y);
    int area () {return (x*y);}
}

public static void main(String[] args) {

Rectangle rect=new Rectangle(3,4);

}

In C++ compiler will create rect object & reserve memory 4 bytes. I want to know How Java is creating object?

© Stack Overflow or respective owner

Related posts about java

Related posts about c++