0

programming languages Online Quiz - 214

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

Who can access a method if it is marked as protected internal ?

  1. Classes that are both in the same assembly and derived from the declaring class.

  2. Only methods that are in the same class as the method in question.

  3. Classes within the same assembly, and classes derived from the declaring class.

  4. Classes in different assembly


Correct Option: C

From the xml comments in the files in an assembly which compiler switch creates an xml file ?

  1. /text

  2. /doc

  3. /xml

  4. /help


Correct Option: B

Output of this program : class type { int num=12; void setnum(int num){ num=num; } int getnum() { return num; } public static void main(String[] args){ type obj=new type(); obj.setnum(10); System.out.print(obj.getnum()); } }

  1. 10

  2. 12

  3. compilation error

  4. none of these


Correct Option: B

Boolean size :

  1. 8 bit

  2. 1 bit

  3. machine dependent

  4. none of these


Correct Option: C

Correct way of method declaration within interface :

  1. void run();

  2. protected void go();

  3. public abstract set();

  4. none of these


Correct Option: A

Which one is true :

  1. interface declares constant and instance variables.

  2. The abstract modifier can be combined with the static modifier .

  3. native modifier can be applied only on method.

  4. synchronized modifier can be applied to method as well as class

  5. none of these


Correct Option: C

Which program will give correct output :

  1. class cons{ cons() { } public void cons(); public static void main (String[] aa){ cons b=new cons(); } }

  2. public class cons { ............... cons() { } public cons(int x,int y) { System.out.print(x +" "+ y); } public static void main (String[] aa){ cons b=new cons(); cons obj=new cons(4,2); }

  3. public class cons { public cons(int x) { System.out.print(x); } public static void main (String[] aa){ cons b=new cons(); } }

  4. class cons{ cons() { } public float foo () { double f = 32; return f; } public static void main (String[] aa){ cons b=new cons(); } }


Correct Option: B

Output of this program : class type { int num=12; void setnum(int num){ num=num; } int getnum() { return num; } public static void main(String[] args){ type obj=new type(); obj.setnum(10); System.out.print(obj.getnum()); } }

  1. 10

  2. 12

  3. compilation error

  4. none of these


Correct Option: B

AI Explanation

To answer this question, let's go through the program step by step:

  1. The program defines a class named "type".
  2. Inside the class, there is an integer variable "num" initialized with the value 12.
  3. The class also contains two methods - "setnum" and "getnum".
  4. The "setnum" method takes an input parameter "num" and assigns it to the same-named instance variable "num" of the class.
  5. The "getnum" method simply returns the value of the instance variable "num".
  6. In the main method, an object of the class "type" is created using the "new" keyword and assigned to the variable "obj".
  7. The "setnum" method of the "obj" object is called with the argument 10, which should set the value of the instance variable "num" to 10.
  8. Finally, the "getnum" method of the "obj" object is called, and the result is printed.

Based on the above explanation, the correct answer is B) 12.

The reason is that the "setnum" method parameter has the same name as the instance variable "num". So when the "num" parameter is assigned to itself using num=num;, it creates a conflict within the method, and the instance variable "num" is not updated. As a result, the value of "num" remains 12, which is the initial value assigned to it. Therefore, when the "getnum" method is called, it returns the value 12.

Boolean size :

  1. 8 bit

  2. 1 bit

  3. machine dependent

  4. none of these


Correct Option: C

Correct way of method declaration within interface :

  1. void run();

  2. protected void go();

  3. static void get();

  4. public abstract set();

  5. none of these


Correct Option: A

Which one is true :

  1. interface declares constant and instance variables.

  2. The abstract modifier can be combined with the static modifier .

  3. native modifier can be applied only on method.

  4. synchronized modifier can be applied to method as well as class.

  5. none of these


Correct Option: C

Which program will give correct output :

  1. class cons{ cons() { } public void cons(); public static void main (String[] aa){ cons b=new cons(); } }

  2. public class cons { cons() { } public cons(int x,int y) { System.out.print(x +" "+ y); } public static void main (String[] aa){ cons b=new cons(); cons obj=new cons(4,2); } }

  3. public class cons { public cons(int x) { System.out.print(x); } public static void main (String[] aa){ cons b=new cons(); } }

  4. class cons{ cons() { } public float foo () { double f = 32; return f; } public static void main (String[] aa){ cons b=new cons(); } }


Correct Option: B

What is the output of the following code when compiled and run? Select two correct answers. public class TechnoSample { public static void main(String[] args){ for(int i = 0; i <> System.out.println(getPrimitive(127)); //line 1 } } public static int getPrimitive(byte b) { //line 2 return (short)(Math.random()*b); //line 3 } }

  1. Compilation error on line 1

  2. Compilation error on line 2

  3. Compilation error on line 3

  4. Line 3 compiles fine

  5. Prints 10 random numbers between 0 and 127


Correct Option: A,D

Select three correct statements.

  1. A static method may override another static method

  2. A static method cannot override a non-static method

  3. A non-static method cannot override a static method

  4. A non-static method may be overloaded by a static method

  5. A synchronized method cannot be overridden


Correct Option: B,C,D

Select three correct statements about the following code :-- public class TechnoSample { public static void main(String[] args) { TechnoSample myref = new TechnoSampleSub(); try{ myref.test(); } catch(Exception e){} } void test() throws Exception{ System.out.println("In TechnoSample"); throw new Exception(); } } class TechnoSample Sub extends TechnoSample { void test() { System.out.println("In TechnoSampleSub"); } }

  1. The try-catch block that encloses myref.test(); is mandatory for the code to compile

  2. Prints: In TechnoSample

  3. Prints: In TechnoSampleSub

  4. Method test() in class TechnoSampleSub has no obligation to declare a throws clause

  5. An exception is thrown at runtime


Correct Option: A,C,D

What will be output for the following program? public class Boxing2 { public static void main(String[] args) { byte b = 10; method(b); } static void method(int i){ System.out.println("Primitivae Type call"); } static void method(Integer i){ System.out.println("Wrapper Type Call"); } }

  1. Wrapper Type Call

  2. Primitive Type Call

  3. Compiler Error

  4. Compiles fine, throws runtime exception


Correct Option: B

What will be the output of the following program? package wrapper_boxing; public class WrapperTest2 { public static void main(String[] args) { Boolean bool1 = new Boolean(true); Boolean bool2 = new Boolean(false); Boolean bool3 = new Boolean("false"); Boolean bool4 = new Boolean(bool1); System.out.println(bool1.equals(bool4)); System.out.println(bool2 == bool3); System.out.println(bool1 == bool4); } }

  1. The program will not compile because the creation of bool4 object will cause compilation error.

  2. The program will produce the output 'true false false'.

  3. The program will produce the output 'true true true'.

  4. The program will output 'true false true'.


Correct Option: B

What will be the output of the following program? import java.io.ByteArrayInputStream; import java.io.InputStream; public class Ques04 { public static void main(String[] args) throws Exception{ byte buffer[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; InputStream inputStream = new ByteArrayInputStream(buffer); inputStream.read();inputStream.read(); inputStream.skip(4); System.out.println((char)inputStream.read()); } }

  1. The program will raise a run-time exception telling that it is not possible to skip bytes in the middle of a reading operation.

  2. The program will output 'd'.

  3. The program will output 'e'.

  4. The program will output 'g'.


Correct Option: D

It is possible to write the simple types directly to a binary file using the methods in the FileStream class.

  1. True

  2. False


Correct Option: A
- Hide questions