Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Lokesh Varma

Greenhorn
+ Follow
since Dec 30, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lokesh Varma

@Elchin Asgarli
Well said Asgarli....your explanation made me smile.
void deleteSharpen(Sharpen sharpen)
{
sharpen = null;
sharpen = new Sharpen();
sharpen.setName("mothulla");
}

In the above function the argument "sharpen" is local to method. It is shadowing the instance variable "sharpen". You are making local variable to NULL. change the argument to any other name as shown below:

void deleteSharpen(Sharpen sharpen1).....you will get output "mothulla"
Toast eye = new Toast();
new Devil(eye).honey(eye);
new Boast(eye).honey(eye);
new Toast().honey(eye);

Above three lines produces the output.

Toast eye = new Toast(); Toast default constructor calls Boast no-arg constructor. Boast constructor calls Devil's no-arg constructor. No parent class to Devil so its no-arg constructor prints "devil" then Boast no-arg constructor prints "boast".

same exlanation : new Devil(eye).honey(eye); doe not print any thing.

new Boast(eye).honey(eye); prints "devil"

new Toast().honey(eye); prints "devil", "boast".....hope this helps