aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading or Overriding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading or Overriding?" Watch "Overloading or Overriding?" New topic

Overloading or Overriding?

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340

There is a little bit of confusion in Overloading and Overriding...
If kindly anyone could help.
See below:

My questions are:
- Are the two methods overloaded or overriden?
- Why is the method of Over class called and not that of below class


[ September 11, 2005: Message edited by: Barry Gaunt ]

Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
sorry for previous code....
i have modified it now

(Modified Code)

why is the method of below class not called ..?
[ September 11, 2005: Message edited by: Sandeep Chhabra ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Since you have now modified your code, I have removed posts that could be considered misleading. I cannot remove the first post because the whole thread would go away.

There is no overriding here because the both the methods called method have different parameter types. The method caller in class over can only see the method method which takes an Exception as parameter. So that is the one that gets called.
[ September 11, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 978

but why does the method in class over is called for the line


here overloading comes into picture but the b object has the scope of the method the beolw class,..

Then why the method in over is called ???

anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
I want to know why the
code gives the following error method1() has private access in A
a.method1();//should print hi2
1 error

i wanna know why this error occurs because a.method1() will invoke method1() of class B.

Thanks and Regards, Anand
SCJP 5.0 310-055 73%, SCWCD 1.4 310-081 78%, IBM DB2 9 Fundamentals 000-730 62%
Joseph Clark
Ranch Hand

Joined: Sep 10, 2005
Posts: 48
A a is invoking B::method1(). B's method1() is unavailable to A a because method1() is marked private.
tarun sundriyal

Joined: Sep 12, 2005
Posts: 2
It is going to print hi1 as u r using an object of class a to reference object of class B so the object dosent have any idea about methods of class B. Therefore it is going to print hi1 instead of hi2

tarun sundriyal

Joined: Sep 12, 2005
Posts: 2
sorry i havent seen private in front of method1() since it is private therefore cannot be accessed by ovbject of type a
I agree. Here's the link:
subject: Overloading or Overriding?
Similar Threads
damn overriding again
Method Overloading and overriding
obj instanceof (String [] )