Programming Interview Questions and Answers



1. How will a class protect the code inside it ?

A. Using access specifier

B. Abstraction

C. Use of inheritance

D. All of the mentioned

Answer : A. Using access specifier




2. Palak enters a coding competition she wants to write code to pass down values from one class to another. Which of following concept should she use to do so ?

A. Inherits

B. Extends

C. Construct

D. All of the mentioned

Answer : B. Extends




3. Tarun wants to write code for his computer class homework but he had misheard the teacher and only can recollect remembering this 4 words. Which of the following is what he couldn’t have had heard ?

A. Distributive

B. Multilevel

C. Multiple

D. Hierarchical

Answer : A. Distributive




4. Tarun works all night long writing code and writing more and more classes for each object he now thinks that he can write a superclass which defines some hierarchical feature for other classes, what can he use ?

A. Cascading

B. Hierarchical super positioning

C. Inheritance

D. Polymorphism

Answer : C. Inheritance




5. Which of the following are available only in the class hierarchy chain ?

A. Public data members

B. Private data members

C. Protected data members

D. Member functions

Answer : C. Protected data members




6. Which of the following cannot be inherited ?

A. Friend

B. Static

C. Destructor

D. Constructor

Answer : C. Destructor




7. A 8-bit signed integer has the following range ?

A. 0 to 255

B. -128 to 127

C. -255 to 254

D. 0 to 509

Answer : B. -128 to 127




8. What will the output of the following code statements be ?
Integer x = 34.54, y = 20, z = -5 print (y > 50 AND z > 10 or x > 30) ?

A. 0

B. 1

C. -1

D. 10

Answer : B. 1




9. I have a problem to solve that takes n as an input number. The problem has a property that given the solution for (n-1), I can easily solve the problem for n. Which programming technique will I use to solve such a problem ?

A. Iteration

B. Decision-making

C. Object Oriented Programming

D. Recursion

Answer : D. Recursion




10. Given : integer x = 40, y = 35, z = 20, w = 10. Comment about the output of the following two statements:
print x * y / z – w
print x * y / (z – w) ?

A. Differ by 80

B. Same

C. Differ by 50

D. Differ by 160

Answer : A. Differ by 80




11. Data and function in which area of a class are directly accessible outside the class ?

A. Public

B. Private

C. Protected

D. None of these

Answer : A. Public




12. What is the time complexity of adding three matrices of size NXN cell-by-cell ?

A. O(N)

B. O(N2)

C. O(N3)

D. None of these

Answer : B. O(N2)




13. Here is an infix notation: ((A+B)*C-(D-E))^(F+G)
Choose the correct postfix notation of the above from the given options ?

A. AB+CD*E–FG+^

B. AB+C*DE–FG+^

C. AB+C*DE-FG-+^

D. A+BC*DE-FG-+^

Answer : B. AB+C*DE–FG+^




14. Which type of inheritance needs a virtual function ?

A. Multi level inheritance

B. Multiple inheritance

C. Hybrid inheritance

D. All of the above

Answer : D. All of the above




15. A code with θ(n) and θ(n2) complexity. Which code will execute faster for a code of size J ?

A. θ(n)

B. θ(n2)

C. Cant be said as size of K is unknown

D. Both will be equal

Answer : C. Cant be said as size of K is unknown




16. There are 2 buildings and on each’s window, a flower pot is kept. Ravi’s mother tells him to multiply each cell/window to the other and store in a matrix ? What would be time complexity if he writes a code to do so ?

A. Omega(n)

B. Omega(n2)

C. Theta (n)

D. Theta (n2)

Answer : D. Theta (n2)




17. What is space complexity of the program ?

A. Amount of hard disk space required to store the program

B. Amount of hard disk space required to compile the program

C. Amount of memory required by the program to run

D. Amount of memory required by the program to compile

Answer : C. Amount of memory required by the program to run






Related Searches to Programming Interview Questions and Answers