The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 283 Weeks Ago |
| Questions Answered: | 27237 |
| Tutorials Posted: | 27372 |
MCS,MBA(IT), Pursuing PHD
Devry University
Sep-2004 - Aug-2010
Assistant Financial Analyst
NatSteel Holdings Pte Ltd
Aug-2007 - Jul-2017
Make sure you understand correctly before answering.
Â
1. Given:
Â
public class Calculator {Â Â Â Â int num = 100;Â Â Â Â public void calc(int num) {Â Â Â Â Â Â Â Â this.num = num * 10;Â Â Â Â Â Â Â
   }
   public void printNum(){        System.out.println(num);
   }
   public static void main(String[] args) {        Calculator obj = new Calculator ();        obj.calc(2);        obj.printNum();
   }
}Â
Â
What is the result?
Â
A)Â 20
B)Â 100
C) 1000
D) 2
Â
Â
2. Given:
Â
public class MyStuff {Â Â Â Â String name;Â Â Â Â MyStuff(String n) {Â Â Â Â Â Â Â Â name = n;
   }
   public static void main(String[] args) {        MyStuff m1 = new MyStuff("guitar");
       MyStuff m2 = new MyStuff("tv");
       System.out.println(m2.equals(m1));
   }
   public boolean equals(Object o) {        MyStuff m = (MyStuff) o;        if (m.name != null) {            return true;
       }
       return false;
   }
}
Â
What is the result?
Â
A)Â The output is true and MyStuff fulfills the Object.equals()contract.
B)Â The output is false and MyStuff fulfills the Object.equals() contract.
C)Â The output is true and MyStuff does NOT fulfill the Object.equals() contract.
D)Â The output is false and MyStuff does NOT fulfill the Object.equals() contract.
Â
Â
3. Given:
Â
import java.util.*; public class App {
   public static void main(String[] args) {        List p = new ArrayList();
       p.add(7);
       p.add(1);
       p.add(5);
       p.add(1);
       p.remove(1);
       System.out.println(p);
   }
}
Â
What is the result?
Â
A)[7, 1, 5, 1]
B)[7, 5, 1]
C)[7, 5]
D)[7, 1]
Â
Â
4. Given:
Â
public class MyLoop {Â Â Â Â public static void main(String[] args) {Â Â Â Â Â Â Â Â String[] sa = {"tom ", "jerry "};Â Â Â Â Â Â Â Â for (int x = 0; x < 3; x++) {Â Â Â Â Â Â Â Â Â Â Â Â for (String s : sa) {Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â System.out.print(x + " " + s);Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (x == 1) {Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
               }
           }
       }
   }
}Â
Â
What is the result?
Â
A)Â 0 tom 0 jerry 1 tom 1 jerry
B)Â 0 tom 0 jerry 2 tom 2 jerry
C) 0 tom 0 jerry 1 tom 2 tom 2 jerry
D) 0 tom 0 jerry 1 tom 1 jerry 2 tom 2 jerry
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
5. Given:
Â
interface Rideable { String getGait(); } public class Camel implements Rideable {Â Â Â Â int weight = 2;
   String getGait() { return " mph, lope"; }    void go(int speed) {        ++speed; weight++;        int walkrate = speed * weight;
       System.out.print(walkrate + getGait());
   }
   public static void main(String[] args) {        new Camel().go(8);
   }
}
Â
What is the result?
Â
A)Â 16 mph, lope
B)Â 24 mph, lope
C) 27 mph, lope
D) Compilation fails.
Â
Â
6. Given:Â
Â
class Alpha {Â Â Â Â String getType() {Â Â Â Â Â Â Â Â return "alpha";
   }
}
Â
class Beta extends Alpha {Â Â Â Â String getType() {Â Â Â Â Â Â Â Â return "beta";
   }
}
Â
public class Gamma extends Beta {Â Â Â Â String getType() {Â Â Â Â Â Â Â Â return "gamma";
   }Â
   public static void main(String[] args) {
       Gamma g1 = new Alpha();
       Gamma g2 = new Beta();
       System.out.println(g1.getType() + " "
               + g2.getType());
   }
}
Â
What is the result?Â
Â
A)Â alpha beta
B)Â beta beta
C) gamma gamma D) Compilation fails.
Â
7. Given:Â
Â
class Feline {Â Â Â Â public String type = "f ";Â Â Â Â public Feline() {
       System.out.print("feline ");
   }
}
Â
public class Cougar extends Feline {Â Â Â Â public Cougar() {
       System.out.print("cougar ");
   }    void go() {        type = "c ";
       System.out.print(this.type + super.type);
   }
   public static void main(String[] args) {        new Cougar().go();
   }
}
Â
What is the result?Â
Â
A)Â cougar c f
B)Â feline cougar c c
C) feline cougar c f
D) Compilation fails.
Â
Â
Â
Â
Â
Â
Â
Â
Â
----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll