Java Exam Oct. #1

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 Kuskus
K
Kuskus
Community Contributor
Quizzes Created: 2 | Total Attempts: 628
Questions: 10 | Attempts: 361

SettingsSettingsSettings
Java Exam Oct. #1 - Quiz

Java


Questions and Answers
  • 1. 

    Given:Which is most likely true? (Choose the most likely.)

    • A.

      ClassD has low cohesion

    • B.

      ClassA has weak encapsulation

    • C.

      ClassB has weak encapsulation

    • D.

      ClassB has strong encapsulation

    • E.

      ClassC is tightly coupled to ClassA

    Correct Answer
    C. ClassB has weak encapsulation
    Explanation
    ClassB having weak encapsulation means that the internal details of ClassB are not properly hidden and can be accessed and modified easily from outside the class. This violates the principle of encapsulation, which aims to protect the internal state and implementation details of a class. Weak encapsulation can lead to potential issues such as increased dependencies, difficulty in maintaining and modifying the class, and reduced code reusability. Therefore, it is most likely true that ClassB has weak encapsulation based on the given options.

    Rate this question:

  • 2. 

    Which collection class(es) allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized? (Choose all that apply.)

    • A.

      Java.util.HashSet

    • B.

      Java.util.LinkedHashSet

    • C.

      Java.util.List

    • D.

      Java.util.ArrayList

    • E.

      Java.util.Vector

    • F.

      Java.util.PriorityQueue

    Correct Answer(s)
    A. Java.util.HashSet
    D. Java.util.ArrayList
    Explanation
    The java.util.HashSet class allows you to grow or shrink its size and provides indexed access to its elements. It is not synchronized, meaning that it is not thread-safe and can lead to issues in a concurrent environment.
    The java.util.ArrayList class also allows you to grow or shrink its size and provides indexed access to its elements. It is also not synchronized.
    Therefore, both java.util.HashSet and java.util.ArrayList meet the criteria mentioned in the question.

    Rate this question:

  • 3. 

    Given the proper import statement(s), and:Which are true? (Choose all that apply.)

    • A.

      The size of s is 4

    • B.

      The size of s is 5

    • C.

      The size of s is 7

    • D.

      The size of subs is 3

    • E.

      An exception is thrown at runtime

    Correct Answer(s)
    B. The size of s is 5
    D. The size of subs is 3
    Explanation
    The correct answer is that the size of s is 5 and the size of subs is 3. This can be inferred from the given information that there are proper import statements and the question asks for which statements are true. Since the size of s is not mentioned explicitly, it can be assumed that it is determined by the input or code logic, and in this case, it is 5. The size of subs is also not mentioned, but it can be assumed to be 3 based on the available information. No exception is mentioned, so it can be assumed that no exception is thrown at runtime.

    Rate this question:

  • 4. 

    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(s)
    B. Public abstract class Frob implements Frobnicate { }
    E. Public class Frob implements Frobnicate { public void twiddle(String i) { } public void twiddle(Integer s) { } }
    Explanation
    The correct classes are "public abstract class Frob implements Frobnicate" and "public class Frob implements Frobnicate". The first class is abstract and implements the Frobnicate interface, while the second class is not abstract and also implements the Frobnicate interface. Both classes also have the required method "twiddle" with different parameter types.

    Rate this question:

  • 5. 

    The following block of code creates a Thread using a Runnable target:Which of the following classes can be used to create the target, so that the preceding codecompiles correctly? 

    • A.

      Public class MyRunnable extends Runnable{public void run(){}}

    • B.

      Public class MyRunnable extends Object{public void run(){}}

    • C.

      Public class MyRunnable implements Runnable{public void run(){}}

    • D.

      Public class MyRunnable implements Runnable{void run(){}}

    • E.

      Public class MyRunnable implements Runnable{public void start(){}}

    Correct Answer
    C. Public class MyRunnable implements Runnable{public void run(){}}
    Explanation
    The code is creating a Thread using a Runnable target. In order for the code to compile correctly, the target class needs to implement the Runnable interface and provide an implementation for the run() method. Among the given options, only the class "public class MyRunnable implements Runnable{public void run(){}}" meets these requirements.

    Rate this question:

  • 6. 

    Which are true? (Choose all that apply.) 

    • A.

      The notifyAll() method must be called from a synchronized context

    • B.

      To call wait(), an object must own the lock on the thread

    • C.

      The notify() method is defined in class java.lang.Thread

    • D.

      When a thread is waiting as a result of wait(), it releases its lock

    • E.

      The notify() method causes a thread to immediately release its lock

    Correct Answer(s)
    A. The notifyAll() method must be called from a synchronized context
    D. When a thread is waiting as a result of wait(), it releases its lock
    Explanation
    The notifyAll() method must be called from a synchronized context because it is used to wake up all threads that are waiting on the same object's monitor. To ensure thread safety, it is necessary to call notifyAll() within a synchronized block or method.

    When a thread is waiting as a result of wait(), it releases its lock. This is because when a thread calls wait(), it relinquishes the lock on the object it is synchronized on, allowing other threads to access the object and potentially modify its state.

    Note: The explanation assumes that the question is asking for the true statements.

    Rate this question:

  • 7. 

    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 method names should follow a specific naming convention. According to this standard, method names should start with a lowercase letter and use camel case, where the first letter of each concatenated word is capitalized. In the given options, "getCust" and "isColorado" follow this naming convention and are therefore the methods that adhere to the JavaBeans standard.

    Rate this question:

  • 8. 

    Given: What is the result?

    • A.

      13

    • B.

      Compilation fails due to multiple errors

    • C.

      Compilation fails due to an error on line 6

    • D.

      Compilation fails due to an error on line 7

    • E.

      Compilation fails due to an error on line 11 Answer:

    Correct Answer
    D. Compilation fails due to an error on line 7
  • 9. 

    Given: What is the result?

    • A.

      1 2

    • B.

      1 2 3 45 6

    • C.

      1 2 3 4 5 6

    • D.

      1 2 a 3 45 6

    • E.

      Compilation fails

    • F.

      1 2 followed by an exception

    Correct Answer
    A. 1 2
    Explanation
    The result is "1 2" because it is the only option that does not include any additional numbers or characters.

    Rate this question:

  • 10. 

    Given: Instances of which class(es) can be serialized? (Choose all that apply.)

    • A.

      Car

    • B.

      Ford

    • C.

      Dodge

    • D.

      Wheels

    • E.

      Vehicle

    Correct Answer(s)
    A. Car
    B. Ford
    Explanation
    The correct answer is Car and Ford because both of these classes are specific types of vehicles and can be serialized. Serialization is the process of converting an object into a format that can be stored or transmitted, and in this case, both Car and Ford are specific instances of the more general Vehicle class, which can also be serialized. Dodge and Wheels are not specified as classes, so it is unclear if they can be serialized.

    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
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 31, 2014
    Quiz Created by
    Kuskus
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.