0

programming languages Online Quiz - 128

Description: programming languages Online Quiz - 128
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Which of the following statements are true?

  1. Methods cannot be overriden to be more private

  2. static methods cannot be overloaded

  3. private methods cannot be overloaded

  4. An overloaded method cannot throw exceptions not checked in the base class


Correct Option: A

Which of the following will output -4.0

  1. System.out.println(Math.floor(-4.7));

  2. System.out.println(Math.round(-4.7));

  3. System.out.println(Math.ceil(-4.7));

  4. System.out.println(Math.min(-4.7));


Correct Option: C
Explanation:

To solve this question, the user needs to understand the difference between the Math.floor(), Math.round(), Math.ceil(), and Math.min() methods in Java.

  • Math.floor() returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
  • Math.round() returns the closest long or int, as given by the methods of the same name, to the argument, with ties rounding to positive infinity.
  • Math.ceil() returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
  • Math.min() returns the smaller of two double values as an argument.

Now, let's go through each option and determine which one will output -4.0:

A. System.out.println(Math.floor(-4.7));

  • This option will output -5.0 because Math.floor() returns the largest double value that is less than or equal to the argument, which in this case is -5.0.

B. System.out.println(Math.round(-4.7));

  • This option will output -5 because Math.round() returns the closest long or int to the argument, which in this case is -5.

C. System.out.println(Math.ceil(-4.7));

  • This option will output -4.0 because Math.ceil() returns the smallest double value that is greater than or equal to the argument, which in this case is -4.0.

D. System.out.println(Math.min(-4.7));

  • This option will not compile because Math.min() requires two arguments, and only one is given.

Therefore, the answer is:

The Answer is: C

String s=new String("Bicycle"); int iBegin=1; char iEnd=3; System.out.println(s.substring(iBegin,iEnd));

  1. Bic

  2. ic

  3. icy

  4. error: no method matching substring(int,char)


Correct Option: B

AI Explanation

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

Option A) Bic This option is incorrect because the substring method in Java uses a zero-based index. In this case, iBegin is 1 and iEnd is 3. The substring method will return a substring starting from the index specified by iBegin (inclusive) and ending at the index specified by iEnd (exclusive). Therefore, the resulting substring will include the characters at index 1 and 2, which are 'i' and 'c', respectively.

Option B) ic This option is correct because the substring method will return a substring starting from the index specified by iBegin (inclusive) and ending at the index specified by iEnd (exclusive). In this case, iBegin is 1 and iEnd is 3. Therefore, the resulting substring will include the characters at index 1 and 2, which are 'i' and 'c', respectively.

Option C) icy This option is incorrect because the substring method will return a substring starting from the index specified by iBegin (inclusive) and ending at the index specified by iEnd (exclusive). In this case, iBegin is 1 and iEnd is 3. Therefore, the resulting substring will include the characters at index 1 and 2, which are 'i' and 'c', respectively. It will not include the character at index 3, which is 'y'.

Option D) error: no method matching substring(int,char) This option is incorrect because the substring method in Java accepts two integer parameters as arguments - the starting index and the ending index. It does not accept a character as the second argument. Therefore, the code will not compile and will result in a compilation error.

The correct answer is B) ic. This option is correct because the substring method will return a substring starting from the index specified by iBegin (inclusive) and ending at the index specified by iEnd (exclusive), which in this case includes the characters 'i' and 'c'.

What is the result of the following operation? System.out.println(4 | 3);

  1. 6

  2. 0

  3. 1

  4. 7


Correct Option: D

Given the following declarations String s1=new String("Hello") String s2=new String("there"); String s3=new String(); Which of the following are legal operations?

  1. s3=s1 + s2

  2. s3=s1 - s2

  3. s3=s1 & s2

  4. s3=s1 && s2


Correct Option: A
Explanation:

To solve this question, the user needs to know the basics of Java String operations.

Option A: s3=s1 + s2

This is a legal operation. The + operator can be used to concatenate two strings. In this case, s1 and s2 are concatenated and the result is stored in s3.

Option B: s3=s1 - s2

This is an illegal operation. The - operator is not defined for strings in Java.

Option C: s3=s1 & s2

This is an illegal operation. The & operator is a bitwise operator and cannot be used with strings in Java.

Option D: s3=s1 && s2

This is an illegal operation. The && operator is a logical operator and cannot be used with strings in Java.

Therefore, the legal operation is:

The Answer is: A

What gets printed when the following code is compiled and run. Select the one correct answer. public class test { public static void main(String args[]) { int i = 1; do { i--; } while (i > 2); System.out.println(i); } }

  1. 0

  2. 1

  3. 2

  4. -1


Correct Option: A
Explanation:

To solve this question, the user needs to understand the basic concept of a do-while loop in Java. The loop executes the code block at least once, even if the condition is initially false. The user must evaluate the code block inside the loop to determine what value is assigned to the variable i and printed to the console.

In this code, the loop decrements the value of i by 1 until i is no longer greater than 2. Since i is initially 1, it will be decremented to 0 before the condition fails and the loop ends. Therefore, the correct answer is:

The Answer is: A. 0

How are this() and super() used with constructors?

  1. This() is used to invoke a constructor of the same class. super() cannot invoke a superclass constructor.

  2. Super() is used to invoke a constructor of the same class. This() is used to invoke a superclass constructor.

  3. This() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

  4. None of the above.


Correct Option: C

Identify the steps to integrate validator framework in struts? a)Copy validation.xml and validation rules.xml to web-inf directory b)Add errors in resource bundle c)Include validation plug-ins in struts- config.xml d)Add validation plug-ins in web.xml and struts-config.xml e)Add validation plug ins in web.xml f)Include the required form in tag in validation.xml g)include required fields in tag in validation.xml

  1. a,f,g,b

  2. a,g,b

  3. a,b,c,d,e,f

  4. c,a,f,g,b

  5. e,a,f,g,b

  6. d,a,f,g,b


Correct Option: D

We can have more than one validation.xml in an application?

  1. True

  2. False


Correct Option: A

Which one we prefer in validating dynamic row functionality of our application?

  1. Javascript

  2. struts validator

  3. cannot validate

  4. dynamic rows cannot be done in JSP


Correct Option: A

How you will display validation fail errors on jsp page?

  1. none

  2. both


Correct Option: C

We can create our our own custom validations in Struts Validator framework?

  1. True

  2. False


Correct Option: A

Which of the following will give the output as 3?

  1. (abs (sqrt 8))

  2. (modulo (ceiling (sqrt 8)) 2)

  3. (max (floor (sqrt 8)) (round (sqrt 8)))

  4. (min (truncate (sqrt 8)) (abs (sqrt 8)))


Correct Option: C

(define myList (list 1 2 3 4 5 6 7 8 9)) (- (+ (list-ref mylist 2) (cadr mylist)) (list-ref (cddr mylist) 2)) Output of the above code will be:

  1. 1

  2. -1

  3. 5

  4. 0


Correct Option: D

Which of the following codes will NOT give an error? (i) (display '(1 2 3)) (ii) (display (* (exp 5 2) 2)) (iii) (display (* (expt 5 2) 2)) (iv) (display (+ 5 (display (* 4 2))))

  1. (i) & (ii)

  2. (i) & (iii)

  3. (i) only

  4. (i), (iii) & (iv)


Correct Option: B

6.What is output of following: ((lambda x x) 1 2 3)

  1. (1 2 3)

  2. 6

  3. 3

  4. (1 2)


Correct Option: A

3.What is output of following? (define a 97) (integer->char (exact->inexact a))

  1. #\97

  2. #\b

  3. #\a

  4. Compile time error


Correct Option: D

(modulo -15 4) the output will be:

  1. 3

  2. -3

  3. 1

  4. -1


Correct Option: C

(define list1 (list 1 2 3)) (define list2 (list 4 5 6)) (define list3 (list)) (append list3 list1 list2) what will be the output if we display list3?

  1. ((1 2 3 4 5 6))

  2. (1 2 3 4 5 6)

  3. ()

  4. (4 5 6 1 2 3)


Correct Option: C
- Hide questions