File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static oveloaded methods with different argument list 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 "Static oveloaded methods with different argument list" Watch "Static oveloaded methods with different argument list" New topic
Author

Static oveloaded methods with different argument list

dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
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.

Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
hey use code tages....


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
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

Joined: Dec 10, 2009
Posts: 521
is the answer 434?
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
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

Joined: Sep 12, 2008
Posts: 90
Raju Champaklal wrote:is the answer 434?


Yes it is output: -434
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
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

Joined: Dec 10, 2009
Posts: 521
you need to read k&b properly...

dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
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

Joined: Dec 10, 2009
Posts: 521
bingo.....
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

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)


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

I've changed that code as follow :


Result : - 134
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Raju Champaklal wrote:bingo.....


I think i am on right track ?
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
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

Joined: Apr 07, 2009
Posts: 489

ok dude..
Thanks..
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
static methods are mot called with any object parameter or dot operator.

Because they belong to the Whole class.
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Leonardo Carreira wrote:ok dude..
Thanks..


the answer is -434.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
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.


SCJP 1.6 96%
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

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..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static oveloaded methods with different argument list
 
Similar Threads
Explanation ....
Study Guide 6 -- Chapter2 Self Test Question 15 on page 181.
Var Args,Arrays and overloading
Self Test doubt
SCJP 1.6 Chapter2 Question 15- Answer -> is D ,I think it should be E