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

finalize method is used to release system resources.

  1. True

  2. False


Correct Option: A

A local variable in a block may be re-declared in another local block, if the blocks are disjoint.

  1. True

  2. False


Correct Option: A

All loops are controlled by a boolean expression.

  1. True

  2. False


Correct Option: A

Which type of Statements can execute parameterized queries?

  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

Constructors can have a return type.

  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

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

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.

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

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