Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overload Java Data Field Type by Another Field Type

Tags:

java

Is it possible to overload a field type to be another field type?

If so, would it be possible to provide some examples?

like image 412
Brandon Wilson Avatar asked Jul 13 '12 16:07

Brandon Wilson


People also ask

Can fields be overloaded in Java?

You can't overload fields (only methods can be overloaded), you might be confused with overriding fields - which anyway is not possible, you end up hiding the fields from superclasses.

Can I override field?

Fields can't be overridden; they're not accessed polymorphically in the first place - you're just declaring a new field in each case. It compiles because in each case the compile-time type of the expression is enough to determine which field called number you mean.

When the same method name is used for more than one method then the name is?

The practice of defining more than one method in a class with same name is called method overloading.


1 Answers

You can't overload fields (only methods can be overloaded), you might be confused with overriding fields - which anyway is not possible, you end up hiding the fields from superclasses. Take a look at this post.

like image 111
Óscar López Avatar answered Oct 02 '22 17:10

Óscar López