What a wasteI have better things to readUmm...seems fineI am lovin itThis was delicious (2 votes, average: 3 out of 5)
Loading ... Loading ...

Method overriding and overloading in Java

July 4th, 2008

I know this may be trivial for many people but then it can be pretty confusing for new bees (pssst.. in the beginning me too used to be confused between overloading and overriding)

OVERRIDING - when you extend a class and write a method in the derived class which is exactly similar to the one present in the base class, it is termed as overriding.

Example:

public class BaseClass{

public void methodToOverride()

{

//Some code here

}

}

public class DerivedClass extends BaseClass{

public void methodToOverride()

{

//Some new code here

}

}

As you can see, in the class DerivedClass, we have overridden the method present in the BaseClass with a completely new piece of code in the DerivedClass.

What that effectively means is that if you create an object of DerivedClass and call the methodToOverride() method, the code in the derivedClass will be executed. If you hadn’t overridden the method in the DerivedClass then the method in the BaseClass would have been called.

OVERLOADING -  when you have more than one method with the same name but different arguments, the methods are said to be overloaded.

Example:

public class OverLoadingExample{

public void add(int i, int j)

{

int k = i + j;

}

public void add(String s, String t)

{

int k = Integer.parseInt(s) + Integer.parseInt(t);

}

}

As you can see in the example above, we have the same method add() taking two parameters but with different data types. Due to overloading we can now call the add method by either passing it a String or int :)

What a wasteI have better things to readUmm...seems fineI am lovin itThis was delicious (1 votes, average: 1 out of 5)
Loading ... Loading ...

Page submits twice when background = “#”

June 7th, 2008

If you ever come across a situation where your page goes to the same action twice for no apparent reason then make sure that there’s no background=”#” anywhere in your page.

I found that if there’s background=”#” then the page tends to submit the same request twice!! Call it a bug in html… Not sure about that. But the code is as below:

<table background=”#”>

<tr>

<td>

This piece of code in your page will cause the request to be submitted twice!!

</td>

</tr>

</table>

Please leave a comment if you have anything to add to this :)

What a wasteI have better things to readUmm...seems fineI am lovin itThis was delicious (No Ratings Yet)
Loading ... Loading ...

Technical site reviews… What do you think?

May 27th, 2008

I am planning to start a blog (review.techtamasha.com) where I review all the other good technical sites, blogs and all kinds of softwares that will help you make your job as a developer or blogger a lot easier. I’ll keep you posted when I start it and it’s gonna be soon ;o)