hi,
i've been solving these multiple choice questions, and i'd like to know if what i answered is right ot wrong......... just to double check :)
I) Consider the code given below.
Which of the following, if inserted at the comment //Here will allow the code to compile and run without error
(a) b=m;
(b) m=b;
(c) d =i;
(d) b1 =i;
- chose (a) because a variable which is declared as a base class can also take instances of subclasses, whereas a variable that's declared as a subclass cannot be set to a superclass.
(II) Given the following variables which of the following lines will compile without error?
String s = "Hello";
long l = 99;
double d = 1.11;
int i = 1;
int j = 0;
(a) j= i <<s;
(b) j= i<<j;
(c) j=i<<d;
(d) j=i<<l;
- I chose (b) because you can't shift by a long, double, or a string.
thanks,
carly :D
i've been solving these multiple choice questions, and i'd like to know if what i answered is right ot wrong......... just to double check :)
I) Consider the code given below.
Code:
class Base{} public class MyCast extends Base{ static boolean b1=false; static int i = ‐1; static double d = 10.1; public static void main(String argv[]){ MyCast m = new MyCast(); Base b = new Base(); //………..Here }}
(a) b=m;
(b) m=b;
(c) d =i;
(d) b1 =i;
- chose (a) because a variable which is declared as a base class can also take instances of subclasses, whereas a variable that's declared as a subclass cannot be set to a superclass.
(II) Given the following variables which of the following lines will compile without error?
String s = "Hello";
long l = 99;
double d = 1.11;
int i = 1;
int j = 0;
(a) j= i <<s;
(b) j= i<<j;
(c) j=i<<d;
(d) j=i<<l;
- I chose (b) because you can't shift by a long, double, or a string.
thanks,
carly :D
Comment