Storm Zcm

Greenhorn
+ Follow
since Jul 08, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Storm Zcm

i'm sorry ,
i have changed my display name.
And I'll use only english in the forum.
[Edit: non-English text elided. Please post only English.]

Refer to which methods to choose in overloading.
in my opinion.

First of all, the compiler consider exact the same.
the method's name must be the same,then the parameters's number must be the same,then the location and parameters type must be the same.
If all of these is the same, then choose this methods.

If there's implicit conversion.
It follow the
(byte,char,short)->int->long->float->double
to judge the parameters.

If there's reference types.
First find the reference type,the find whether is the subclass of the reference type.

In J2SE 5.0, there's auto-boxing. Then to judge the parameters.

[ July 17, 2008: Message edited by: Bear Bibeault ]
[ July 17, 2008: Message edited by: Bear Bibeault ]
In a class, there are a lot of methods with the same name and their parameters's number is also the same.
what's the algorithm that java choose method?

when there are implicit change,explicit change,boxing.
what's the algorithm that java choose method?
Sekhar Kadiyala
Thanks for answer. I get it.
public class MyClass {

/** Creates a new instance of MyClass */
public MyClass() {
}

public static void main(String[] args) {
final int i = 100;//#1
byte b = i;
System.out.println("b:"+b);
}
}

it run correctly.
but if you replace #1 to int i = 100;
it can't compile.
what's the reason?
Thank you for reply.I know than you can't use a reference of the protected instance if they are not in the same package.
What i means is that if you place "static" modifier before "protected",you can use a reference of the protected instance.
What's the reason?
package pack;

public class Pack {
static public int x1 = 7;
protected int x2 = 8;//#1
static int x3 = 9;
static private int x4 = 10;
}

import pack.Pack;

public class Test extends Pack {
Test(){
try{
throw new RuntimeException();
}finally{
System.out.println("runtime");
}
}
public static void main(String[] args){
Pack p = new Pack();
System.out.println(p.x2);
}
}

why #1 x2 can be accessed?
if you delete "static" modifier,then x2 is invisible?
can someone explain why?
thank you in advance^^
Thanks for your reply.
Maybe JVM doesn't so clever as i think
class sup{
void method() throws Exception{
System.out.println("sup");
}
}
public class NewMain1 extends sup{

/** Creates a new instance of NewMain1 */
public NewMain1() {
}
@Override
void method(){
System.out.println("new");
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{//#1
// TODO code application logic here
sup s = new NewMain1();
s.method();
}

}
why we should throws Exception at #1?
Overload method() doesn't throws Excpetions?

best wishes.
I find that the inner class's instance variable can't be autoinitialized.
Are there any other differences?

best wishes.