• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Static oveloaded methods with different argument list

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

i am the code as :

class A {}
class B extends A{}

public class Test
{
static String s = "- ";

public static void main(String args[])
{

A[] aa = new A[2];

B[] bb=new B[2];

sifter(aa);

sifter(bb);

sifter(7);

System.out.println(s);

}

static void sifter(A[] ....a2) { s += "1"; }

static void sifter(B[] ....b1) { s += "2"; }


static void sifter(B[] b1) { s += "3"; }

static void sifter(Object 0) { s += "4"; }


}

I am not able to get red part of the code.

Thank you.

 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey use code tages....
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raju Champaklal wrote:hey use code tages....



Does mean sifter(aa) object is passed thr sifter(Object 0) --------> 4 (lets take object is passed )

but what abt other sifter(bb) means sifter(B[] b1)---------->3 ?

sifter(7) ---------?

not able to resolved the tages.

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is the answer 434?
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
7 is an int and it is boxed to Integer and then widened to Object.....boxing and widening is taking place
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raju Champaklal wrote:is the answer 434?



Yes it is output: -434
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raju Champaklal wrote:7 is an int and it is boxed to Integer and then widened to Object.....boxing and widening is taking place



i am not aware of Boxing and widening ?

I have gone thr CHP 2 which has obj 1.5 but ......

how sifter(ba) goes with sifter(B[] b1)

b1 is another reference variable of class B[] ? i think yes.

Thank you.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to read k&b properly...

 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raju Champaklal wrote:you need to read k&b properly...



I think i got it . it goes
In

sifter(bb)----------> sifter(B[] b1)

I am passing the object bb which belongs to array B[] referncing alongwith the other object referenece b1.

In other words bb and b1 are referncing to same array B[].
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bingo.....
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..


Are you sure with this code?..
that code must be couldn't be compiled..
because we can't declare Formal Parameter with . (dot) or 0 (zero)
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've changed that code as follow :


Result : - 134
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raju Champaklal wrote:bingo.....



I think i am on right track ?
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leonardo Carreira wrote:I've changed that code as follow :


--------- There is no need to change the code .

code is correct.





Result : - 134

 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok dude..
Thanks..
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static methods are mot called with any object parameter or dot operator.

Because they belong to the Whole class.
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leonardo Carreira wrote:ok dude..
Thanks..



the answer is -434.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leonardo Carreira wrote:I've changed that code as follow :


Result : - 134



look at your modified code properly you have removed one method from the original code and replaced the one method:
static void sifter(A[] ... aa){ s += "1";} with static void sifter(A[] a2){ s += "1";}

so with this code answer is -134 but with original one answer will be -434.
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.. i got it...

with this code, i can't compile this..



then i tried to "repaired" that code, as bellow, and it could gets compile :


that's why, in my first post, i asked whether that code is true..
yes, i've tested the code, and the result is 434..
sorry for silly mistake, that makes me misunderstanding it..
 
reply
    Bookmark Topic Watch Topic
  • New Topic