Help coderanch get a
new server
by contributing to the fundraiser

ailina nagarawati

Greenhorn
+ Follow
since Jul 25, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by ailina nagarawati

E is correct but F is wrong because

in choice E:

E. Replace lines 17�20 with
Integer total = accountTotals.get(accountName);
if (total == null) total = 0;
return total;

the total is checked whether its null
if its null, then total will be 0

whereas in choice F:

Replace lines 17�20 with
return accountTotals.get(accountName);

there is not any checking whether the total is null
if the total is null, the value returned for the method "getBalance" which is supposed to be "int" IS NOT compatible with the "null" value of the total. and "null" cannot be unbox to 0

hope that helps
Hi,

i come across this question:

given:
package sun.scjp;

public enum Color { RED, GREEN, BLUE}

package sun.beta;
//insert code here

public class Beta{
Color g= GREEN;
public static void main(String [] args){
System.out.println(GREEN);}
}
}

The class Beta and the enum Color are in different packages.
Which two code fragments, inserted individually at line 2 of the Beta declaration,
will allow this code to compile? (choose 2)

a. import sun.scjp.Color.*;
b. import static sun.scjp.Color.*;
c. import sun.scjp.Color; import static sun.scjp.Color.*;
d. import sun.scjp.*; import static sun.scjp.Color.*;
e. import sun.scjp.Color; import static sun.scjp.Color.GREEN;

My answer is C and D, while the correct answer is C and E.
How? D and E looks the same.. Can anyone give me a clear explanation about this?

appreciate your help
For example,

you create an anonymous class

Foo f= new Foo(){};

so a static reference variable refers to an instance of an anonymous class will be:

static Foo sf;
sf=f

hope that helps
Hi,

overloading basically means you modify a method so that it can accept different arguments.. (arguments are the variables inside the bracket)

for example:
you have a method:

public void doSomething(int a, int b){}

if you overload it so that the method can accept "double type" arguments, you might have something like this:
public void doSomething(double a, double b){}

for more info:
http://java.ittoolbox.com/documents/popular-q-and-a/overloading-and-overriding-3699