Scjp (310-055) Exam I

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Billdotnet
B
Billdotnet
Community Contributor
Quizzes Created: 2 | Total Attempts: 1,769
Questions: 12 | Attempts: 135

SettingsSettingsSettings
Scjp (310-055) Exam I - Quiz


Self-study questions for Sun Certified Java Programmer (SCJP) (310-055). God speed!


Questions and Answers
  • 1. 

    Given the following, 1. interface Base {2. boolean m1 ();3. byte m2(short s);4. } Which code fragments will compile? (Choose all that apply.)

    • A.

      Interface Base2 implements Base { }

    • B.

      Abstract class Class2 extends Base { public boolean ml() { return true; } }

    • C.

      Abstract class Class2 implements Base { }

    • D.

      # abstract class Class2. implements Base { public boolean m1() { return (true); } }

    • E.

      Class Class2 implements Base { boolean m1( ) { return false; } byte m2(short s) { return 42; } }

    Correct Answer(s)
    C. Abstract class Class2 implements Base { }
    D. # abstract class Class2. implements Base { public boolean m1() { return (true); } }
    Explanation
    The code fragment "abstract class Class2 implements Base { }" will compile because it correctly implements the interface Base. The code fragment "abstract class Class2. implements Base { public boolean m1() { return (true); } }" will also compile because it correctly implements the interface Base and provides an implementation for the m1() method.

    Rate this question:

  • 2. 

    Which declare a compilable abstract class? (Choose all that apply.)

    • A.

      Public abstract class Canine { public Bark speak(); }

    • B.

      Public abstract class Canine { public Bark speak() { } }

    • C.

      Public class Canine { public abstract Bark speak(); }

    • D.

      Public class Canine abstract { public abstract Bark speak(); }

    Correct Answer
    B. Public abstract class Canine { public Bark speak() { } }
    Explanation
    The correct answer is "public abstract class Canine { public Bark speak() { } }". This is the correct answer because it declares an abstract class "Canine" with a method "speak()" that returns a "Bark" object. The class is marked as abstract and the method is implemented with an empty body, indicating that it must be overridden by any concrete subclass.

    Rate this question:

  • 3. 

    Which is true? (Choose all that apply. )

    • A.

      "X extends Y" is correct if and only if X is a class and Y is an interface.

    • B.

      "X extends Y" is correct if and only if X is an interface and Y is a class.

    • C.

      "X extends Y" is correct if X and Y are either both classes or both interfaces.

    • D.

      "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.

    Correct Answer
    C. "X extends Y" is correct if X and Y are either both classes or both interfaces.
    Explanation
    The statement "X extends Y" is correct if X and Y are either both classes or both interfaces. This means that if X is a class, then Y must also be a class. Similarly, if X is an interface, then Y must also be an interface. If X and Y are of different types (one class and one interface), the statement is not correct. However, if they are both of the same type, the statement holds true.

    Rate this question:

  • 4. 

    Which are valid declarations? (Choose all that apply.)

    • A.

      Int $x;

    • B.

      Int 123;

    • C.

      Int _123;

    • D.

      Int #dim;

    • E.

      Int central_sales_region_Summer_2005_gross_sales;

    Correct Answer(s)
    A. Int $x;
    C. Int _123;
    E. Int central_sales_region_Summer_2005_gross_sales;
    Explanation
    The valid declarations in this question are int $x;, int _123;, and int central_sales_region_Summer_2005_gross_sales;. The first declaration, int $x;, is valid because it starts with a valid character, the dollar sign. The second declaration, int _123;, is valid because it starts with a valid character, the underscore. The last declaration, int central_sales_region_Summer_2005_gross_sales;, is valid because it starts with a valid character, a letter. The other declarations, int 123; and int #dim;, are not valid because they start with a number and a pound sign, respectively, which are not allowed in variable names.

    Rate this question:

  • 5. 

    Which method names follow the JavaBeans standard? (Choose all that apply.)

    • A.

      AddSize

    • B.

      GetCust

    • C.

      DeleteRep

    • D.

      IsColorado

    • E.

      PutDimensions

    Correct Answer(s)
    B. GetCust
    D. IsColorado
    Explanation
    The JavaBeans standard states that getter and setter methods should follow a specific naming convention. The methods should start with "get" or "set" followed by the name of the property with the first letter capitalized. In this case, the method names "getCust" and "isColorado" follow this convention and are therefore correct according to the JavaBeans standard.

    Rate this question:

  • 6. 

    Given:1. class Voop {2. public static void main(String [] args) {3. doStuff(1);4. doStuff(1, 2);5. }6. // insert code here7. } Which, inserted independently at line 6, will compile? (Choose all that apply.)

    • A.

      Static void doStuff(int... doArgs) { }

    • B.

      Static void doStuff (int [] doArgs) { }

    • C.

      Static void doStuff(int doArgs...) { }

    • D.

      Static void doStuff(int... doArgs, int y) { }

    • E.

      Static void doStuff(int x, int... doArgs) { }

    Correct Answer(s)
    A. Static void doStuff(int... doArgs) { }
    E. Static void doStuff(int x, int... doArgs) { }
    Explanation
    The correct answer is static void doStuff(int... doArgs) { }, static void doStuff(int x, int... doArgs) { }. These two options will compile because they both use the varargs syntax (int... doArgs) which allows for a variable number of arguments to be passed to the method. The first option does not have any additional parameters, while the second option has an additional parameter (int x) before the varargs parameter.

    Rate this question:

  • 7. 

    Which statement(s) are true? (Choose all that apply.)

    • A.

      Has-a relationships always rely on inheritance.

    • B.

      Has-a relationships always rely on instance variables.

    • C.

      Has-a relationships always require at least two class types

    • D.

      Has-a relationships always rely on polymorphism.

    • E.

      Has-a relationships are always tightly coupled.

    Correct Answer
    B. Has-a relationships always rely on instance variables.
    Explanation
    Has-a relationships in object-oriented programming refer to the relationship between classes where one class has a reference to another class as an instance variable. This allows the class to access the methods and properties of the other class. Therefore, the statement "Has-a relationships always rely on instance variables" is true. It is important to note that has-a relationships do not necessarily rely on inheritance, require at least two class types, rely on polymorphism, or are always tightly coupled.

    Rate this question:

  • 8. 

    Given: class Clidders { public final void flipper() { System.out.println("Clidder"); }}public class Clidlets extends Clidders { public void flipper() { System.out.println("Flip a Clidlet"); super.flipper(); } public static void main(String [] args) { new Clidlets().flipper(); }} What is the result?

    • A.

      Flip a Clidlet

    • B.

      Flip a Clidde

    • C.

      Flip a Clidder Flip a Clidlet

    • D.

      # Flip a Clidlet Flip a Clidder

    • E.

      Compilation fails.

    Correct Answer
    E. Compilation fails.
    Explanation
    The code fails to compile because the final keyword is used in the method declaration of the flipper() method in the Clidders class. This means that the method cannot be overridden in any subclass. However, in the Clidlets class, the flipper() method is attempting to override the flipper() method from the superclass, which is not allowed due to the final keyword. Therefore, the code fails to compile.

    Rate this question:

  • 9. 

    Given: public abstract interface Frobnicate { public void twiddle(String s) ; } Which is a correct class? (Choose all that apply.)

    • A.

      Public abstract class Frob implements Frobnicate { public abstract void twiddle(String s){} }

    • B.

      Public abstract class Frob implements Frobnicate { }

    • C.

      Public class Frob extends Frobnicate { public void twiddle(Integer i) { } }

    • D.

      Public class Frob implements Frobnicate { public void twiddle(Integer i) { } }

    • E.

      Public class Frob implements Frobnicate { public void twiddle(String i) { } public void twiddle(Integer s) { } }

    Correct Answer
    B. Public abstract class Frob implements Frobnicate { }
    Explanation
    The correct answer is "public abstract class Frob implements Frobnicate { }". This class correctly implements the Frobnicate interface by using the "implements" keyword and providing an empty implementation for the twiddle() method. Additionally, the class is declared as abstract, which is allowed since the interface is also declared as abstract.

    Rate this question:

  • 10. 

    Given: class Top { public Top(String s) { System.out.print("B"); }}public class Bottom2 extends Top { public Bottom2(String s) { System.out.print("D"); } public static void main(String [] args) { new Bottom2("C"); System.out.println(" "); }}What is the result?

    • A.

      BD

    • B.

      DB

    • C.

      BDC

    • D.

      DBC

    • E.

      Compilation fails.

    Correct Answer
    E. Compilation fails.
    Explanation
    The code fails to compile because the constructor of the class Bottom2 does not explicitly call the constructor of its superclass, Top. Since the superclass, Top, does not have a default constructor, the code fails to compile.

    Rate this question:

  • 11. 

    Select the two statements that best indicate a situation with low coupling. (Choose two.)

    • A.

      The attributes of the class are all private.

    • B.

      The class refers to a small number of other objects.

    • C.

      The object contains only a small number of variables.

    • D.

      The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.

    • E.

      It is unlikely that changes made to one class will require any changes in another.

    Correct Answer(s)
    D. The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.
    E. It is unlikely that changes made to one class will require any changes in another.
    Explanation
    A situation with low coupling is indicated by the reference variable being declared for an interface type, not a class, and the interface providing a small number of methods. This suggests that the class is not tightly coupled to specific implementations and can easily work with different objects that adhere to the same interface. Additionally, if changes made to one class do not require any changes in another class, it implies that the classes are loosely coupled and can be modified independently without affecting each other.

    Rate this question:

  • 12. 

    Given: class Clidder { private final void flipper() { System.out.println ("Clidder"); }}public class Clidlet extends Clidder { public final void flipper() { System.out.println("Clidlet"); } public static void main(String [] args) { new Clidlet().flipper(); }} What is the result?

    • A.

      Clidlet

    • B.

      Clidder

    • C.

      Clidder Clidlet

    • D.

      Clidlet Clidder

    • E.

      Compilation fails.

    Correct Answer
    A. Clidlet
    Explanation
    The result is "Clidlet" because the method flipper() in the Clidlet class overrides the method in the parent class Clidder. When the new Clidlet object is created and the flipper() method is called, it executes the override method in Clidlet, which prints "Clidlet" to the console.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • May 08, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 09, 2010
    Quiz Created by
    Billdotnet
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.