0

programming languages Online Quiz - 194

Description: programming languages Online Quiz - 194
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0
  1. PreparedStatement

  2. ) ParameterizedStatement

  3. ) ParameterizedStatement and CallableStatement

  4. All the above


Correct Option: A

A method can not have the same name as another method in the same class.

  1. True

  2. False


Correct Option: B

Any class that implements the Runnable interface has to provide the implementation for the following methods public void start(); public void run();

  1. True

  2. False


Correct Option: B

A thread that has called the wait() method of an object still owns the lock of the object.

  1. True

  2. False


Correct Option: B

If you call the interrupted() method of a thread object twice the second call will always return false.

  1. True

  2. False


Correct Option: B

A number of threads of the same priority have relinquished the lock on a monitor and are in a waiting state after having called the wait() method of the object. A new thread enters the monitor and calls the notifyAll() method of the meonitor. Which of these threads will be the first one to resume?

  1. The thread that has been waiting the longest.

  2. The thread that was the last one to to exit the monitor.

  3. You can never be sure which thread will get to run first.

  4. The the first thread that called the wait() method


Correct Option: C
  1. public Thread(Object obj)

  2. public Thread(String name)

  3. public Thread(Runnable trgt)

  4. public Thread(ThreadGroup grp, Runnable trgt, String name)

  5. public Thread(ThreadGroup grp, Object ob)


Correct Option: B,C,D

class Line { Line 1. public class Point { public int x,y; } Line 2. public Point getPoint() { return new Point(); } Line 3. } Line 4. class Triangle { Line 5. public Triangle() { Line 6. // insert code here Line 7. } 18. } Which code, inserted at line Line 6, correctly retrieves a local instance of a Point object? A. Point p = Line.getPoint(); B. Line.Point p = Line.getPoint(); C. Point p = (new Line()).getPoint(); D. Line.Point p = (new Line()).getPoint();

  1. A

  2. B

  3. C

  4. D


Correct Option: D

public class test { Line 1. public static void main(String [] a) { Line 2. assert a.length == 1; Line 3. } Line 4. } Which two will produce an AssertionError? (Choose two.) A. java test B. java -ea test C. java test file1 D. java -ea test file1 E. java -ea test file1 file2 F. java -ea:test test file1

  1. AB

  2. BC

  3. AE

  4. BE


Correct Option: D

Given a method that must ensue that its parameter is not null: Line 1. public void someMethod(Object value) { Line 2. // check for null value Line 3. System.out.println(value.getClass()); Line 4. } What, inserted at line 2, is the appropriate way to handle a null value? A. assert value == null; B. assert value !null, “value is null”; C. if (value == null) { throw new AssertionException(”value is null”); D. if (value == null) { throw new IllegalArgumentException(”value is null”);

  1. A

  2. B

  3. C

  4. D


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) A. assert value == null; - This option is incorrect because the assert statement is used for debugging purposes and is typically disabled in production code. It is not an appropriate way to handle a null value.

Option B) B. assert value !null, “value is null”; - This option is incorrect because the syntax is incorrect. The correct syntax for checking if a value is not null is value != null (without the exclamation mark).

Option C) C. if (value == null) { throw new AssertionException(”value is null”); - This option is incorrect because AssertionException is not a standard exception in Java. It is not appropriate to throw an assertion-specific exception to handle a null value.

Option D) D. if (value == null) { throw new IllegalArgumentException(”value is null”); - This option is correct because IllegalArgumentException is a standard exception in Java that is commonly used to indicate that an argument passed to a method is invalid. Throwing an IllegalArgumentException with an appropriate error message is an appropriate way to handle a null value in this context.

The correct answer is D. This option is correct because it uses the appropriate exception (IllegalArgumentException) to handle a null value.

Line 1. public class ClassA { Line 2. public void count(int i) { Line 3. count(++i); Line 4. } Line 5. } And: Line 6. ClassA a = new ClassA(); Line 7. a.count(3); Which exception or error should be thrown by the virtual machine? A. StackOverflowError B. NullPointerException C. NumberFormatException D. IllegalArgumentException E. ExceptionlnlnitializerError

  1. A

  2. B

  3. C

  4. D


Correct Option: D

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

  1. public abstract class Canine { public Bark speak(); }

  2. public abstract class Canine { public Bark speak() { } }

  3. public class Canine { public abstract Bark speak(); }

  4. public class Canine abstract { public abstract Bark speak(); }


Correct Option: B

AI Explanation

To answer this question, we need to understand the concept of abstract classes and how they are declared in Java.

An abstract class is a class that cannot be instantiated and is meant to be extended by other classes. It may contain abstract methods, which are methods without any implementation, as well as regular methods with implementations.

Let's go through each option to understand why it is correct or incorrect:

Option A) public abstract class Canine { public Bark speak(); } This option is incorrect because the abstract method "speak()" is not given an implementation. Abstract methods must be implemented in the concrete subclass that extends the abstract class.

Option B) public abstract class Canine { public Bark speak() { } } This option is correct because it declares an abstract class "Canine" with a concrete method "speak()" that returns a "Bark" object. The method implementation can be empty, as long as it is provided.

Option C) public class Canine { public abstract Bark speak(); } This option is incorrect because the class "Canine" is not declared as abstract, but it contains an abstract method "speak()". Abstract methods can only exist in abstract classes.

Option D) public class Canine abstract { public abstract Bark speak(); } This option is incorrect because the keyword "abstract" should come before the class name, not after it. The correct syntax is "public abstract class Canine".

The correct answer is B. This option is correct because it declares an abstract class "Canine" with a concrete method "speak()" that returns a "Bark" object, even though the implementation is empty.

Which is true? (Choose all that apply. )

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

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

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

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


Correct Option: C

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

  1. addSize

  2. getCust

  3. deleteRep

  4. isColorado

  5. putDimensions


Correct Option: B,D

AI Explanation

To answer this question, we need to understand the JavaBeans standard. The JavaBeans standard is a design pattern for writing reusable and customizable components in Java. According to this standard, the names of methods in JavaBeans should follow specific conventions.

Let's go through each option to determine if it follows the JavaBeans standard:

A. addSize - This method name does not follow the JavaBeans standard. According to the standard, getter and setter methods should have names that start with "get" and "set" respectively.

B. getCust - This method name follows the JavaBeans standard. It starts with "get" and is followed by a capitalized property name ("Cust"). This naming convention is used for getter methods.

C. deleteRep - This method name does not follow the JavaBeans standard. According to the standard, getter and setter methods should have names that start with "get" and "set" respectively.

D. isColorado - This method name follows the JavaBeans standard. It starts with "is" and is followed by a capitalized property name ("Colorado"). This naming convention is used for boolean getter methods.

E. putDimensions - This method name does not follow the JavaBeans standard. According to the standard, getter and setter methods should have names that start with "get" and "set" respectively.

Therefore, the method names that follow the JavaBeans standard are B. getCust and D. isColorado.

- Hide questions