Java and C++ Programming Fundamentals

Test your knowledge of core programming concepts including OOP principles, exception handling, pointers, and preprocessor directives in Java and C++.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

1)main() { int i = 5; printf(“%d %d %d %d %d”,i++,i--,++i,--i,i); }

  1. 5 6 6 5 5
  2. 6 5 6 5 5
  3. 5 5 6 5 5
  4. 4 5 5 4 5
Question 2 Multiple Choice (Single Answer)

1)void main() { int const *p = 5; printf(“%d”,++(*p)); }

  1. 6
  2. junk value
  3. some address
  4. error
Question 3 Multiple Choice (Single Answer)

1)#define square(x) x*xmain(){ int i; i=64/square(4); printf(“%d”,i);}

  1. 32
  2. 4
  3. 64
  4. 16
Question 4 Multiple Choice (Single Answer)

1)main() { int a[2][3][2]={{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d”,a,*a,**a,***a); printf(“%u %u %u %d\n”,a+1,*a+1,**a+1,***a+1); } Provided base address of a is 100.

  1. 100 100 100 2 112 104 102 3
  2. 100 104 108 3 112 116 120 3
  3. 100 100 100 2 112 104 102 2
  4. 100 104 108 2 112 116 120 2
Question 5 Multiple Choice (Single Answer)

1)main() { static int a[]={0,1,2,3,4}; int *p[]={a,a+1,a+2,a+3,a+4}; int **ptr=p; ptr++; printf(“\n%d%d%d”ptr-p,*ptr-a,**ptr); *ptr++; printf(“\n%d%d%d”ptr-p,*ptr-a,**ptr); *++ptr; printf(“\n%d%d%d”ptr-p,*ptr-a,**ptr); ++*ptr; printf(“\n%d%d%d”ptr-p,*ptr-a,**ptr); }

  1. 123 234 340 012
  2. 111 222 333 444
  3. 111 222 444 333
  4. 012 340 234 123
Question 6 Multiple Choice (Multiple Answers)

Which of the following statements are valid array declaration?

  1. int number();
  2. float average[];
  3. double[] marks;
  4. counter int[];
Question 7 Multiple Choice (Multiple Answers)

Which of the following classes are available in the java.lang package?

  1. Object
  2. Math
  3. Random
  4. Stack
Question 8 Multiple Choice (Multiple Answers)

Which of the following are the wrapper classes?

  1. Byte
  2. Integer
  3. Short
  4. String
Question 9 Multiple Choice (Multiple Answers)

Given the code String s1 = "yes"; String s2 = "yes"; String s3 = new String(s1); Which of the following would equate to true?

  1. s1 == s2
  2. s3 == s1
  3. s1.equals(s2)
  4. s3.equals(s1)
Question 10 Multiple Choice (Multiple Answers)

The methods wait() and notify() are defined in

  1. java.lang.Thread
  2. java.lang.Object
  3. java.lang.Runnable
  4. java.lang.ThreadGroup
Question 11 True/False

An abstract class can have an object defined.

  1. True
  2. False
Question 12 True/False

virtual function defined in the parent class should be redefined in all of its inheriting child classes

  1. True
  2. False
Question 13 True/False

string s="tcs". This is a valid c++ syntax.

  1. True
  2. False
Question 14 True/False

Static global variable in one c++ file can be used in another c++ file with the help of extern keyword.

  1. True
  2. False
Question 15 True/False

“abc” is a primitive value

  1. True
  2. False
Question 16 True/False

A class is a subclass of itself.

  1. True
  2. False
Question 17 True/False

Exceptions can be rethrown.

  1. True
  2. False
Question 18 True/False

void is the return type of a program’s main() method

  1. True
  2. False
Question 19 True/False

non-Unicode letter characters $ and _ cannot be used as the first character of an identifier

  1. True
  2. False
Question 20 True/False

this() is used to invoke a constructor of the same class

  1. True
  2. False