Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about overload

 
Yu-Jie Jang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hollo,everyone:
If must transfer overload , what should noted?
if there type the same , how about casting ?
if casting the same ?
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Yu-Jie Jang:
Hollo,everyone:
If must transfer overload , what should noted?
if there type the same , how about casting ?
if casting the same ?

Hi Yu and welcome to the ranch, i am not trying to be rude here, but can you please clarify what you are saying, cause honestly... i have no idea what you're talking about.
 
Yu-Jie Jang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i missing one question
when I overload :
B extends A
A a=new A();
A b=new B();
if A have private vaiable x and default y,
B have private y and default x,
methed call ?
variable call ?
 
Chao Chihwai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Yu:
After reading what you mentioned, I think your question is not about overload, it may be override.When one class has methods which have same name and different types of arguments, like:
public int method(){};
private double method (int x){};

The question you mentioned can be separate into 2 parts variable and method();
Variale:
Without considering the static or instance variables,when you call the variable, it depends on the type.It means if the code is A a = new B(); when you call a.x or a.y, it will show the class A's variable value.
Method():
1.It is different in static and instance method().First, The static method() can't override instance method() and instance method() can't override static method.
2.If the subclass and it's superclass have same static method();when you call the method();it depends on type like variable(This situation may be called Hide).
3.If the subclass and it's superclass have same instance method();when you call the method();it depends on type like object.It means if the code is A a = new B(); when you call a.x(), it will execute the class B's method().Thos situation may be called override.
Conclude( s = static i = instance)

Please tolerat my poor English, and hope it can help you !
[ December 28, 2003: Message edited by: Chao Chihwai ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic