By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,550 Members | 2,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,550 IT Pros & Developers. It's quick & easy.

Multiple choice questions..

P: 37
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.

Expand|Select|Wrap|Line Numbers
  1.    class Base{} 
  2.     public class MyCast extends Base{ 
  3.         static boolean b1=false; 
  4.         static int i = ‐1; 
  5.         static double d = 10.1; 
  6.         public static void main(String argv[]){ 
  7.              MyCast m = new MyCast(); 
  8.              Base b = new Base(); 
  9.              //..Here 
  10.     }} 
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
Nov 4 '06 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
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.

Expand|Select|Wrap|Line Numbers
  1. class Base{} 
  2. public class MyCast extends Base{ 
  3. static boolean b1=false; 
  4. static int i = ‐1; 
  5. static double d = 10.1; 
  6. public static void main(String argv[]){ 
  7. MyCast m = new MyCast(); 
  8. Base b = new Base(); 
  9. //..Here 
  10. }} 
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
For the first one, with a 1.5 compiler you also get
d =i; as valid. An integer can be stored in a double reference

For the second one, You can shifta long!
Nov 6 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.