wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method call" Watch "method call" New topic
Author

method call

Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Hi, I have given the questions in the comments. Please advice.
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
What do you think the difference is?

What happened when you tried? What do you mean by "right" way?
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
My assumptions are as given below.
Line#4- Not clear
Line#5 - We are adding an instance of the class(Object) with some memory value/bit pattern.
Line#8 and 9 - I am trying to fetch the elements from super class (ArrayList )because we added to super class add method at Line#4 and 5.
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
Saibabaa Pragada wrote:My assumptions are as given below.
Line#4- Not clear

Why not? What's not clear? What happened when you tried it?

Saibabaa Pragada wrote:Line#5 - We are adding an instance of the class(Object) with some memory value/bit pattern.

I'm not even sure what you mean by this. Why would you want to do that, anyway?

Saibabaa Pragada wrote:Line#8 and 9 - I am trying to fetch the elements from super class (ArrayList )because we added to super class add method at Line#4 and 5.

Okay, and did that work? What happened when you tried? What happened when you took away the super keyword?
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
The reason I'm asking you so many questions is to get you thinking about your own problem. The thing is, I, or anyone with a basic understanding of Java, could answer the questions very easily for you.
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Here is my understanding.
Line #5. I knew that we can add objects (new <some class name>())
Line#4. I am not sure if we can add references also. That's why I asked this question. I haven't seen like this so far.
Line #8, I do not see any difference between System.out.println(get(0)); and System.out.println(super.get(0));
Please let me know if I am not clear.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Saibabaa Pragada wrote:Line #5. I knew that we can add objects (new <some class name>())

No, that's wrong. In that line you are adding a reference to a new object. You aren't adding an object.
Line#4. I am not sure if we can add references also. That's why I asked this question. I haven't seen like this so far.

Yes. In fact you can ONLY add references. Not objects.
Line #8, I do not see any difference between System.out.println(get(0)); and System.out.println(super.get(0));

The former might call the get() method which the class overrides, and the latter would not. But we can't see whether the class overrides get(). If it doesn't, then the two constructs are the same.
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
Saibabaa Pragada wrote:
Line #5. I knew that we can add objects (new <some class name>())
Line#4. I am not sure if we can add references also. That's why I asked this question. I haven't seen like this so far.


Let's look at it this way:

Does the same exact thing as:


Does that help? The reason I asked you so many questions is that this is really easily demonstrated by a simple program that you could have thrown together. That's the best way to learn: by doing. Anyway,

Saibabaa Pragada wrote:Line #8, I do not see any difference between System.out.println(get(0)); and System.out.println(super.get(0));
Please let me know if I am not clear.


If you haven't overridden the get method, then there wouldn't be a difference. But you could have a get(int) function in your subclass, which would then override any calls to get, unless you specified super.get(). Does that make sense?
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Thanks Paul & Kevin. I am giving the conclusion for other ranchers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
Saibabaa Pragada wrote: . . . // Answer: we are adding a reference which pointed to null . . .
What does that mean? Where is the null? That will confuse anybody who comes upon this thread in the future. You appear to have the correct answer to that line, but applied it to the next line.
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
The default value for any object is null. I changed code little bit as given below. Please let me know if you are referring something else
Campbell Ritchie wrote:
Saibabaa Pragada wrote: . . . // Answer: we are adding a reference which pointed to null . . .
What does that mean? Where is the null? That will confuse anybody who comes upon this thread in the future. You appear to have the correct answer to that line, but applied it to the next line.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method call