Tag: programming languages

Questions Related to programming languages

public class test { public static void main(String [] args) { int x = 5; test t = new test(); t.doStuff(x); System.out.print("main x = " + x); } void doStuff(int x) { System.out.print("doStuff x = " + x++); } } What is the result?

  1. doStuff x = 6 main x = 6

  2. doStuff x = 5 main x = 6

  3. doStuff x = 5 main x = 5

  4. Compilation fails


Correct Option: C

AI Explanation

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

  1. In the main method, an integer variable x is declared and assigned the value of 5.
  2. An instance of the test class is created using the new keyword and assigned to the variable t.
  3. The doStuff method of the test class is called with the argument x.
  4. Inside the doStuff method, the value of x is printed, which is initially 5. Then, the x++ expression is evaluated, which increments the value of x by 1.
  5. The main method continues executing after the doStuff method call and prints the value of x, which is still 5.

Therefore, the output of the program is: doStuff x = 5 main x = 5

So, the correct answer is C. doStuff x = 5 main x = 5.

  1. A final method in class X can be abstract if and only if X is abstract.

  2. A private static method can be called only within other static methods in class X.

  3. A protected method in class X can be overridden by any subclass of X.

  4. A non-static public final method in class X can be overridden in any subclass of X.


Correct Option: C
  1. Encapuslation

  2. Abstraction

  3. Information Hiding

  4. Polymorphism


Correct Option: B
  1. Virtual functions

  2. Inline functions

  3. Static functions

  4. Friend functions


Correct Option: B

__________ pointer is a type of pointer of any data type and generally takes a value as zero

  1. Vptr

  2. Void

  3. Null

  4. Zero


Correct Option: C
  1. Automatic

  2. Global

  3. Static

  4. External


Correct Option: A,C,D

A __________function is used for accessing the non-public members of a class.

  1. Static

  2. Virtual

  3. Void

  4. Friend


Correct Option: D

The static member functions have a class scope and they have access to the 'this' pointer of the class.

  1. True

  2. False


Correct Option: B