Sun Certification

  Home  Certifications  Sun Certification


“Sun Certified Java Developer guideline for job interview preparation. Explore list of Sun Certified Java Developer frequently asked questions(FAQs) asked in number of Sun Certified Java Developer interviews. Post your comments as your suggestions, questions and answers on any Sun Certified Java Developer Interview Question or answer. Ask Sun Certified Java Developer Question, your question will be answered by our fellow friends.”



20 Sun Certification Questions And Answers

3⟩ Can you explain Given 5. class Building { } 6. public class Barn extends Building { 7. public static void main(String[] args) { 8. Building build1 = new Building(); 9. Barn barn1 = new Barn(); 10. Barn barn2 = (Barn) build1; 11. Object obj1 = (Object) build1; 12. String str1 = (String) build1; 13. Building build2 = (Building) barn1; 14. } 15. } Which is true? A. If line 10 is removed, the compilation succeeds. B. If line 11 is removed, the compilation succeeds. C. If line 12 is removed, the compilation succeeds. D. If line 13 is removed, the compilation succeeds. E. More than one line must be removed for compilation to succeed.

C: If line 12 is removed, the compilation succeeds.

 199 views

5⟩ Tell me What is native keyword and abstract keyword?

Native keyword is prefixed with method name when we want that method to be implemented using a native language like c and c++. So in the class we only declare the method and the definition of the method is in the dll file.

Abstract key word is used to mark a method or a class as logically incomplete. The class which extends this class has to provide the definition of the method or has to declare the derived class as abstract.

We can not declare a native method inside a interface because by declaring a method in an interface we want all the implementers to give definitions to the methods defined. But by declaring a method native we mean that the implementation will come from some native language.

 199 views

6⟩ Explain Which two statements are true? (Choose two.) A. It is possible for more than two threads to deadlock at once. B. The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state. C. Deadlocked threads release once their sleep() methods sleep duration has expired. D. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly. E. It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly. F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield().

A: It is possible for more than two threads to deadlock at once.

F:If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting

invocations of Thread.yield().

 194 views

8⟩ Explain Given 1. class Super { 2. private int a; 3. protected Super(int a) { this.a = a; } 4. } ... 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a = 5; } 14. } Which two, independently, will allow Sub to compile? (Choose two.) A. Change line 2 to public int a; B. Change line 2 to protected int a; C. Change line 13 to public Sub() { this(5); } D. Change line 13 to public Sub() { super(5); } E. Change line 13 to public Sub() { super(a); }

C:Change line 13 to:

public Sub() { this(5); }

D:Change line 13 to:

public Sub() { super(5); }

 215 views

9⟩ Explain Given 11. public class Rainbow { 12. public enum MyColor { 13. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); 14. private final int rgb; 15. MyColor(int rgb) { this.rgb = rgb; } 16. public int getRGB() { return rgb; } 17. }; 18. public static void main(String[] args) { 19. // insert code here 20. } 21. } Which code fragment, inserted at line 19, allows the Rainbow class to compile? A. MyColor skyColor = BLUE; B. MyColor treeColor = MyColor.GREEN; C. if(RED.getRGB() < BLUE.getRGB()) { } D. Compilation fails due to other error(s) in the code. E. MyColor purple = new MyColor(0xff00ff); F. MyColor purple = MyColor.BLUE + MyColor.RED;

B:MyColor treeColor = MyColor.GREEN;

 171 views

11⟩ Explain Given21. class Money {22. private String country = "Canada";23. public String getC() { return country; }24. }25. class Yen extends Money {26. public String getC() { return super.country; }27. }28. public class Euro extends Money {29. public String getC(int x) { return super.getC(); }30. public static void main(String[] args) {31. System.out.print(new Yen().getC() + " " + new Euro().getC());32. }33. }What is the result?A. CanadaB. null CanadaC. Canada nullD. Canada CanadaE. Compilation fails due to an error on line 26.F. Compilation fails due to an error on line 29.

E:Compilation fails due to an error on line 26.

 178 views

12⟩ Explain Given 1. public class Threads4 { 2. public static void main (String[] args) { 3. new Threads4().go(); 4. } 5. public void go() { 6. Runnable r = new Runnable() { 7. public void run() { 8. System.out.print("foo"); 9. } 10. }; 11. Thread t = new Thread(r); 12. t.start(); 13. t.start(); 14. } 15. } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes normally and prints "foo". D. The code executes normally, but nothing is printed.

B:An exception is thrown at runtime.

 180 views

13⟩ Explain Given 11. public static void parse(String str) { 12. try { 13. float f = Float.parseFloat(str); 14. } catch (NumberFormatException nfe) { 15. f = 0; 16. } finally { 17. System.out.println(f); 18. } 19. } 20. public static void main(String[] args) { 21. parse("invalid"); 22. } What is the result? A. 0.0 B. Compilation fails. C. A ParseException is thrown by the parse method at runtime. D. A NumberFormatException is thrown by the parse method at runtime.

B:Compilation fails.

 193 views

14⟩ Explain Given 5. class Atom { 6. Atom() { System.out.print("atom "); } 7. } 8. class Rock extends Atom { 9. Rock(String type) { System.out.print(type); } 10. } 11. public class Mountain extends Rock { 12. Mountain() { 13. super("granite "); 14. new Rock("granite "); 15. } 16. public static void main(String[] a) { new Mountain(); } 17. } What is the result? A. Compilation fails. B. atom granite C. granite granite D. atom granite granite E. An exception is thrown at runtime. F. atom granite atom granite

F:atom granite atom granite

 184 views

15⟩ Explain Given11. class PingPong2 {12. synchronized void hit(long n) {13. for(int i = 1; i < 3; i++)14. System.out.print(n + "-" + i + " ");15. }16. }17. public class Tester implements Runnable {18. static PingPong2 pp2 = new PingPong2();19. public static void main(String[] args) {20. new Thread(new Tester()).start();21. new Thread(new Tester()).start();22. }23. public void run() { pp2.hit(Thread.currentThread().getId()); }24. }Which statement is true?A. The output could be 5-1 6-1 6-2 5-2B. The output could be 6-1 6-2 5-1 5-2C. The output could be 6-1 5-2 6-2 5-1D. The output could be 6-1 6-2 5-1 7-1

B:The output could be 6-1 6-2 5-1 5-2

 190 views

16⟩ Explain Given 11. public abstract class Shape { 12. private int x; 13. private int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } Which two classes use the Shape class correctly? (Choose two.) A. public class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public abstract class Circle implements Shape { private int radius; public void draw(); } E. public class Circle extends Shape { private int radius; public void draw() {/* code here */} F. public abstract class Circle implements Shape { private int radius; public void draw() { /* code here */ }

B:public abstract class Circle extends Shape {

private int radius;

}

E:public class Circle extends Shape {

private int radius;

public void draw() {/* code here */}

 195 views

17⟩ Explain Given 1. public class Threads2 implements Runnable { 2. 3. public void run() { 4. System.out.println("run."); 5. throw new RuntimeException("Problem"); 6. } 7. public static void main(String[] args) { 8. Thread t = new Thread(new Threads2()); 9. t.start(); 10. System.out.println("End of method."); 11. } 12. } Which two can be results? (Choose two.) A. java.lang.RuntimeException Problem B. run. java.lang.RuntimeException Problem C. End of method. java.lang.RuntimeException Problem D. End of method. run. java.lang.RuntimeException Problem E. run. java.lang.RuntimeException Problem End of method.

D:End of method.

run.

java.lang.RuntimeException: Problem

E:run.

java.lang.RuntimeException: Problem

End of method.

 196 views

18⟩ Suppose A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting? A. Looser coupling B. Tighter coupling C. Lower cohesion D. Higher cohesion E. Weaker encapsulation F. Stronger encapsulation

A:Looser coupling

 184 views

19⟩ Explain Given 11. abstract class Vehicle { public int speed() { return 0; } 12. class Car extends Vehicle { public int speed() { return 60; } 13. class RaceCar extends Car { public int speed() { return 150; } ... 21. RaceCar racer = new RaceCar(); 22. Car car = new RaceCar(); 23. Vehicle vehicle = new RaceCar(); 24. System.out.println(racer.speed() + ", " + car.speed() 25. + ", " + vehicle.speed()); What is the result? A. 0, 0, 0 B. 150, 60, 0 C. Compilation fails. D. 150, 150, 150 E. An exception is thrown at runtime.

D: 150, 150, 150

 191 views

20⟩ Explain Given 1. public class Blip { 2. protected int blipvert(int x) { return 0; } 3. } 4. class Vert extends Blip { 5. // insert code here 6. } Which five methods, inserted independently at line 5, will compile? (Choose five.) A. public int blipvert(int x) { return 0; } B. private int blipvert(int x) { return 0; } C. private int blipvert(long x) { return 0; } D. protected long blipvert(int x) { return 0; } E. protected int blipvert(long x) { return 0; } F. protected long blipvert(long x) { return 0; } G. protected long blipvert(int x, int y) { return 0; }

A:public int blipvert(int x) { return 0; }

C:private int blipvert(long x) { return 0; }

E:protected int blipvert(long x) { return 0; }

F:protected long blipvert(long x) { return 0; }

G:protected long blipvert(int x, int y) { return 0; }

 165 views