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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading or Overriding?" Watch "Overloading or Overriding?" New topic
Author

Overloading or Overriding?

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
HI,

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

Thanx

Sandy
[ 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: 979
Hi,

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


b.caller();

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


Then why the method in over is called ???

Regards
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
I want to know why the
code gives the following error


B.java:19: 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
Greenhorn

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


regards
tarun sundriyal
Greenhorn

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Overloading or Overriding?