• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading or Overriding?

 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joseph Clark
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A a is invoking B::method1(). B's method1() is unavailable to A a because method1() is marked private.
 
tarun sundriyal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i havent seen private in front of method1() since it is private therefore cannot be accessed by ovbject of type a
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic