0

programming languages Online Quiz - 294

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

Given: 1. public class A { 2. public void doit() { 3. } 4. public String doit() { 5. return “a”; 6. } 7. public double doit(int x) { 8. return 1.0; 9. } 10.} What is the result?

  1. An exception is thrown at runtime

  2. Compilation fails because of an error in line 7

  3. Compilation fails because of an error in line 4.

  4. Compilation succeeds and no runtime errors with class A occur


Correct Option: C

Given: 10. class Line { 11. public static class Point { } 12. } 13. 14. class Triangle { 15. // insert code here 16. } Which code, inserted at line 15, creates an instance of the Point class defined in Line?

  1. Point p = new Point();

  2. Line.Point p = new Line.Point();

  3. The Point class cannot be instatiated at line 15

  4. Line 1 = new Line() ; 1.Point p = new 1.Point();


Correct Option: B
Explanation:

To solve this question, the user needs to know how to create an instance of a nested class.

Option A: Point p = new Point(); This option is incorrect because the Point class is a nested static class and must be accessed through the outer class. In this case, the outer class is Line and the correct way to access the nested class is Line.Point.

Option B: Line.Point p = new Line.Point(); This option is correct. Since Point is a nested static class, it can be accessed using the outer class name followed by a dot and the nested class name. This option correctly creates an instance of the Point class defined in Line.

Option C: The Point class cannot be instantiated at line 15. This option is incorrect. The Point class can be instantiated from within the Triangle class, but it must be done using the correct syntax since it is a nested class.

Option D: Line 1 = new Line() ; 1.Point p = new 1.Point(); This option is incorrect because it contains a syntax error. The variable 1 cannot be used as a variable name in Java.

The Answer is: B. Line.Point p = new Line.Point();

Given: 10. class Line { 11. public class Point { public int x,y; } 12. public Point getPoint() { return new Point(); } 13. } 14. class Triangle { 15. public Triangle() { 16. // insert code here 17. } 18. } Which code, inserted at line 16, correctly retrieves a local instance of a Point object?

  1. Point p = Line.getPoint();

  2. Line.Point p = Line.getPoint();

  3. Point p = (new Line()).getPoint();

  4. Line.Point p = (new Line()).getPoint();


Correct Option: D

Given: 10. class One { 11. public One() { System.out.print(1); } 12. } 13. class Two extends One { 14. public Two() { System.out.print(2); } 15. } 16. class Three extends Two { 17. public Three() { System.out.print(3); } 18. } 19. public class Numbers{ 20. public static void main( String[] argv) { new Three(); } 21. } What is the result when this code is executed?

  1. 1

  2. 3

  3. 123

  4. 321


Correct Option: C

AI Explanation

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

Option A) 1 - This option is incorrect because it only prints the value 1, but the code will also print other values.

Option B) 3 - This option is incorrect because it only prints the value 3, but the code will also print other values.

Option C) 123 - This option is correct because the code creates an instance of the class Three in the main method. Since Three extends Two, which extends One, the constructors of One, Two, and Three will be called in that order. The constructors print 1, 2, and 3 respectively, resulting in the output 123.

Option D) 321 - This option is incorrect because it reverses the order of the printed values. The correct order is 123.

The correct answer is C. This option is correct because the code will print the values 1, 2, and 3 in that order, resulting in the output 123.

When comparing java.io.BufferedWriter to java.io.FileWriter, which capabilities exist as a method in only one of the two?

  1. Closing the stream

  2. flushing the stream

  3. writing to the stream

  4. writing a line separator to the stream


Correct Option: D

Output for the below code : int i = 10; while (++i <= 10) { i++; } System.out.print(i);

  1. 10

  2. 11

  3. 12

  4. Line 5 will be never reached


Correct Option: B

touch command can be used for ?

  1. To create a directory

  2. To change timestamp of a file

  3. To edit a file

  4. To create a empty file


Correct Option: A,B,C,D

Command to list the hidden files inside a directory

  1. ls -R

  2. ls -l

  3. ls -a

  4. None of the above


Correct Option: A,B,C,D

Command to delete a directory which contains some files.

  1. rm

  2. rmdir

  3. rmdir -r

  4. rm -r


Correct Option: A,B,C,D

Command to change the permissions of a file

  1. chown

  2. cp

  3. chmod

  4. cd


Correct Option: A,B,C,D

touch command can be used for ?

  1. To create a directory

  2. To change timestamp of a file

  3. To edit a file

  4. To create a empty file


Correct Option: A,B,C,D

Which of the following is NOT a tool used to aid software design?

  1. Flow charts

  2. Pseudocode

  3. Bytecode

  4. UML


Correct Option: C

You have a long night of coding ahead. Which of the following energy drinks offers the most caffeine and sugar per ounce?

  1. Red Bull

  2. Monster

  3. Rockstar

  4. Full Throttle


Correct Option: C

Which of the following is a typical activity that takes place during the process of code refactoring?

  1. Buffer overflows are eliminated

  2. Variables are renamed to provide more meaningful context

  3. Exception handlers are added to catch runtime errors

  4. New features are added based on the latest iterative design changes


Correct Option: B
- Hide questions