• Post Reply Bookmark Topic Watch Topic
  • New Topic

need explanation about constructor  RSS feed

 
riris wijaya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i want to ask about the constructor above. what is the meaning with private Matrix(Matrix A) { this(A.data); } ??? and what is the meaning with Matrix plus(Matrix B)?? is that constructor??? but how is that constructor has return value???
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code has 3 constructors - 2 public, 1 private. Constructors don't have return values.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
riris wijaya wrote:i want to ask about the constructor above. what is the meaning with private Matrix(Matrix A) { this(A.data); } ???

It's a private constructor that creates a new Matrix from an existing one. The
this(A.data);
is a call to
public Matrix(double[][] data)
and is called 'constructor chaining'. This is allowed provided that the call to this(...) is the first line in the constructor doing the call.

and what is the meaning with Matrix plus(Matrix B)?? is that constructor???

No. A constructor always has the same name as its class.

but how is that constructor has return value???

See above.

Winston
 
riris wijaya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer. For mr winston, i want to ask if Matrix plus(Matrix B) is not constructor, then what it is called?? and how its work?
 
Devaka Cooray
Marshal
Posts: 5650
765
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
riris wijaya wrote:... if Matrix plus(Matrix B) is not constructor, then what it is called?? and how its work?

It''s a method. It has a Matrix referenced parameter B, and returns an object with a Matrix reference. You can read more about methods in this tutorial.
 
riris wijaya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if Matrix plus(Matrix B) is a method, then where is data type???
 
Devaka Cooray
Marshal
Posts: 5650
765
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data type? The first Matrix is the return type and the second Matrix is the parameter type. Have you gone through the tutorial I pointed out?
 
Priyank Mehta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still cant find the problem from this program !!
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priyank

What problem are you specifically having? All you have done thus far is ask general questions which have been answered.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priyank Mehta wrote:I still cant find the problem from this program !!


James Boswell wrote:Priyank

What problem are you specifically having? All you have done thus far is ask general questions which have been answered.



Priyank isn't the OP for this topic -- or have asked anything during this topic. I think what Priyank is saying is that the OP didn't ask a question at all. There isn't an issue with the code.

Henry
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priyank

My apologies.

Thanks for making me aware Henry.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!