Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passsing a object reference as parameter

 
ssiva raman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai friends,

here is my question ,

i know that we can pass an object refrence as a argument but how does the caller method declare a parameter of that reference type since this type cannot be defaulty declared as such int,float etc... i looked for examples but they explained it only in standard way like they create an objcet of the particular type class and passing its refrence through the constructor when instantiating an other object of the same class type.



looking for help............
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide a code example of what you are trying to do?
 
ssiva raman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all thankyou for your response.

i was not refering any code.i asked generally but,since you asked,do you know about Throwable constructor in exception handling.how does the subclass exception be passed in to the superclass constructor.what if these class not in inheritance relationship.you got my question?

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just give an example it's much easier to understand your question and discuss about it. Because you can refer to class names, method names, variables,... It makes things much more clear (which results in a better learning experience, not only for you but also for other ranchers).

ssiva raman wrote:do you know about Throwable constructor in exception handling

Yes

ssiva raman wrote:how does the subclass exception be passed in to the superclass constructor

I guess you are referring to this constructor: public Throwable(Throwable cause) {}? With super(). Let's create a custom exception:


ssiva raman wrote:what if these class not in inheritance relationship.

If you pass a value into this constructor which is not a Throwable the code won't compile. So:


1) This line will compile, because IllegalArgumentException is a Throwable.
2) This line will not compile, because StringBuilder is not a Throwable.
 
Stal Alexandr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ssiva raman wrote:how does the subclass exception be passed in to the superclass constructor.


use keyword "super"




ssiva raman wrote:
what if these class not in inheritance relationship.you got my question?


You'll get compilation error at this case.

 
ssiva raman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your replies were amazing and really helped.

using polymorphism i should be let to do the below program but i wasn't.
why?

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code please use code tags next time, I have added them for you this time. It increases the readibility of your post (and you'll have more chance of getting meaningful answers to your queries).

ssiva raman wrote:using polymorphism i should be let to do the below program but i wasn't.

Your example is just a class hierarchy with a superclass and a subclass, no polymorphism at all. Your code does NOT compile, but the error is not on the line you indicated. So please adjust your code snippet accordingly.
 
ssiva raman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see the problem is i couldn't understand the polymorphism concept clearly.you must've noticed that right?
so,if you dont mind could you help me clarify that.i know it's vast.tell me the general rule and let us see if i understand and we carry on our discussion because i've some ideas too.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe a good starting point would be Oracle's Java Tutorial.
 
ssiva raman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'll refer it and get back to you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic