Page 1 of 1

which are true of following code???

Posted: Sat Jan 14, 2017 2:45 am
by sulakshana
Package aquarium.*;
public class Water{
public String toString() { return ""; }
}
Package aquarium.*;
public class Shark{
static int numfins;
static Water water;
public static void Main(String[] args){
String s1 = water.toString();
String s2 = numfins.toString();} }
The answer for this question is numfins.to
String() does not compile because numfins is a primitive;
What is static Water water ; in this question .... Why two water words are used here...

Re: which are true of following code???

Posted: Sun Jan 15, 2017 12:13 am
by admin
Water with capital W is the class name. water with small w is the static variable name. This variable is being declared to be of type Water.

BTW, what happened when you asked your doubt to the author of the book that you have taken this from? Are they not responding?