Tag: programming languages

Questions Related to programming languages

  1. Line 26 prints “a” to System.out

  2. Line 26 prints ‘b” to System.out

  3. An exception is thrown at line 26 at runtime.

  4. Compilation of class A will fail due to an error in line 6


Correct Option: A
Explanation:

To solve this question, the user should understand the concept of method overloading and how Java resolves the method call based on the number and type of arguments passed.

In the given code, class A has two methods named doit. One method takes two integer arguments, and the other takes an arbitrary number of integer arguments.

When we call a.doit(4,5) on line 26, Java examines both methods in class A that are named doit and checks to see which one matches the argument types. Since there is a doit method with two integer parameters, Java selects that method, and the String "a" is returned by that method.

Therefore, the output of the given code is:

The Answer is: A. Line 26 prints “a” to System.out.

  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
  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();

  1. Closing the stream

  2. flushing the stream

  3. writing to the stream

  4. writing a line separator to the stream


Correct Option: D
  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