Programming Concepts Level Pseudocode Questions file 2
Programming Concepts Level Pseudocode Questions file 2
LEVEL PSEUDOCODE
QUESTIONS – COMPANY
ASKED
Fundamental Programming Concepts Tested in IT Companies
Programming Concepts Covered:
1. Object-Oriented Concepts: Inheritance, Polymorphism,
Encapsulation, Abstraction
2. Advanced OOP: Virtual functions, Abstract classes, Interfaces
3. Design Patterns: Singleton, Factory, Observer, Dependency
Injection
4. Generic Programming: Templates, Specialization
5. Concurrency: Threading, Synchronization
6. Memory Management: RAII, Constructors, Destructors
ALGORITHM inheritance_concept
BEGIN
CLASS Animal
name = ""
FUNCTION make_sound()
RETURN "Some generic sound"
END
END CLASS
Options:
ALGORITHM pointer_arithmetic
BEGIN
arr = [10, 20, 30, 40, 50]
ptr = ADDRESS_OF(arr[0])
PRINT VALUE_AT(ptr)
ptr = ptr + 2 // Move pointer by 2 positions
PRINT VALUE_AT(ptr)
Options:
A) 10 30 20
B) 10 20 30
C) 0 2 1
D) Undefined behavior
Question 3 (Deloitte USI - 2023)
What will be the output of this encapsulation pseudocode?
ALGORITHM encapsulation_demo
BEGIN
CLASS BankAccount
PRIVATE balance = 0
Options:
A) 1000
B) 1050
C) Error - private members accessed
D) 0
Question 4 (Oracle India - 2024)
What concept does this constructor pseudocode illustrate?
ALGORITHM constructor_concept
BEGIN
CLASS Student
name = ""
age = 0
grade = ""
CONSTRUCTOR Student()
name = "Unknown"
age = 0
grade = "Not Assigned"
END
CONSTRUCTOR Student(n, a)
name = n
age = a
grade = "Not Assigned"
END
CONSTRUCTOR Student(n, a, g)
name = n
age = a
grade = g
END
END CLASS
student1 = NEW Student()
student2 = NEW Student("John", 20)
student3 = NEW Student("Alice", 22, "A")
PRINT [Link] + " " + [Link] + " " + [Link]
END
Options:
A) Constructor overloading
B) Constructor chaining
C) Default initialization
D) Parameterized constructor
Question 5 (Microsoft India - 2023)
What will this multithreading pseudocode output?
ALGORITHM threading_concept
BEGIN
shared_counter = 0
THREAD thread1()
BEGIN
FOR i = 1 TO 3
LOCK mutex
temp = shared_counter
temp = temp + 1
shared_counter = temp
PRINT "Thread1: " + shared_counter
UNLOCK mutex
END FOR
END
THREAD thread2()
BEGIN
FOR i = 1 TO 2
LOCK mutex
temp = shared_counter
temp = temp + 2
shared_counter = temp
PRINT "Thread2: " + shared_counter
UNLOCK mutex
END FOR
END
START thread1()
START thread2()
WAIT FOR ALL THREADS
PRINT "Final: " + shared_counter
END
Options:
ALGORITHM generic_programming
BEGIN
GENERIC CLASS Stack<T>
items = []
top = -1
int_stack.push(10)
string_stack.push("Hello")
PRINT int_stack.pop()
PRINT string_stack.pop()
END
Options:
A) Generic/Template programming
B) Function overloading
C) Inheritance
D) Polymorphism
Question 7 (Google India - 2023)
What will this lambda/closure pseudocode output?
ALGORITHM closure_concept
BEGIN
FUNCTION outer_function(x)
BEGIN
FUNCTION inner_function(y)
BEGIN
RETURN x + y
END
RETURN inner_function
END
add_five = outer_function(5)
add_ten = outer_function(10)
result1 = add_five(3)
result2 = add_ten(7)
Options:
A) 8 17
B) 5 10
C) 3 7
D) Error - nested functions not allowed
Question 8 (Tata Elxsi - 2024)
What concept does this destructor pseudocode show?
ALGORITHM destructor_concept
BEGIN
CLASS FileHandler
filename = ""
file_pointer = NULL
CONSTRUCTOR FileHandler(name)
filename = name
file_pointer = OPEN_FILE(filename)
PRINT "File opened: " + filename
END
DESTRUCTOR ~FileHandler()
IF file_pointer != NULL THEN
CLOSE_FILE(file_pointer)
PRINT "File closed: " + filename
END IF
END
END CLASS
BEGIN SCOPE
handler = NEW FileHandler("[Link]")
// Some file operations
END SCOPE // handler goes out of scope here
Options:
ALGORITHM operator_overloading
BEGIN
CLASS Complex
real = 0
imaginary = 0
CONSTRUCTOR Complex(r, i)
real = r
imaginary = i
END
OPERATOR + (other)
result_real = real + [Link]
result_imag = imaginary + [Link]
RETURN NEW Complex(result_real, result_imag)
END
FUNCTION display()
RETURN real + " + " + imaginary + "i"
END
END CLASS
c1 = NEW Complex(3, 4)
c2 = NEW Complex(1, 2)
c3 = c1 + c2
PRINT [Link]()
END
Options: A) 4 + 6i
B) 3 + 4i
C) 1 + 2i
D) Error - operator overloading invalid
Question 10 (Paytm - 2023)
What does this interface implementation pseudocode demonstrate?
ALGORITHM interface_concept
BEGIN
INTERFACE Drawable
FUNCTION draw()
FUNCTION get_area()
END INTERFACE
CONSTRUCTOR Circle(r)
radius = r
END
FUNCTION draw()
RETURN "Drawing a circle"
END
FUNCTION get_area()
RETURN 3.14 * radius * radius
END
END CLASS
CONSTRUCTOR Rectangle(w, h)
width = w
height = h
END
FUNCTION draw()
RETURN "Drawing a rectangle"
END
FUNCTION get_area()
RETURN width * height
END
END CLASS
Options:
ALGORITHM event_handling
BEGIN
CLASS Button
click_handlers = []
FUNCTION add_click_handler(handler)
ADD handler TO click_handlers
END
FUNCTION click()
FOR each handler IN click_handlers
handler.handle_click()
END FOR
END
END CLASS
CLASS AlertHandler
message = ""
CONSTRUCTOR AlertHandler(msg)
message = msg
END
FUNCTION handle_click()
PRINT "Alert: " + message
END
END CLASS
button = NEW Button()
handler1 = NEW AlertHandler("First click!")
handler2 = NEW AlertHandler("Second click!")
button.add_click_handler(handler1)
button.add_click_handler(handler2)
[Link]()
END
Options:
ALGORITHM dependency_injection
BEGIN
INTERFACE Logger
FUNCTION log(message)
END INTERFACE
CLASS OrderService
logger = NULL
CONSTRUCTOR OrderService(log_service)
logger = log_service
END
FUNCTION create_order()
[Link]("Order created successfully")
END
END CLASS
Options:
ALGORITHM singleton_pattern
BEGIN
CLASS DatabaseConnection
STATIC instance = NULL
connection_id = 0
FUNCTION get_connection_id()
RETURN connection_id
END
END CLASS
conn1 = DatabaseConnection.get_instance()
conn2 = DatabaseConnection.get_instance()
Options:
ALGORITHM factory_pattern
BEGIN
INTERFACE Vehicle
FUNCTION start()
FUNCTION stop()
END INTERFACE
FUNCTION stop()
RETURN "Car engine stopped"
END
END CLASS
FUNCTION stop()
RETURN "Bike engine stopped"
END
END CLASS
CLASS VehicleFactory
STATIC FUNCTION create_vehicle(type)
IF type = "car" THEN
RETURN NEW Car()
ELSE IF type = "bike" THEN
RETURN NEW Bike()
END IF
RETURN NULL
END
END CLASS
vehicle1 = VehicleFactory.create_vehicle("car")
vehicle2 = VehicleFactory.create_vehicle("bike")
PRINT [Link]()
PRINT [Link]()
END
Options:
ALGORITHM abstract_class
BEGIN
ABSTRACT CLASS Shape
color = "white"
FUNCTION set_color(c)
color = c
END
FUNCTION display_info()
RETURN "Shape color: " + color + ", Area: " + calculate_area()
END
END CLASS
CONSTRUCTOR Circle(r)
radius = r
END
FUNCTION calculate_area()
RETURN 3.14 * radius * radius
END
END CLASS
ALGORITHM method_chaining
BEGIN
CLASS StringBuilder
content = ""
FUNCTION append(text)
content = content + text
RETURN this
END
FUNCTION append_line(text)
content = content + text + "\n"
RETURN this
END
FUNCTION to_string()
RETURN content
END
END CLASS
PRINT result
END
ALGORITHM exception_propagation
BEGIN
FUNCTION level3()
BEGIN
THROW NEW Exception("Error in level 3")
END
FUNCTION level2()
BEGIN
TRY
level3()
CATCH Exception e
PRINT "Caught in level 2: " + [Link]
THROW e // Re-throw the exception
END TRY
END
FUNCTION level1()
BEGIN
TRY
level2()
CATCH Exception e
PRINT "Caught in level 1: " + [Link]
FINALLY
PRINT "Level 1 cleanup"
END TRY
END
level1()
PRINT "Program continues"
END
Options: A) Caught in level 2: Error in level 3, Caught in level 1: Error in level 3, Level 1
cleanup, Program continues
B) Caught in level 2: Error in level 3, Level 1 cleanup, Program continues
C) Error in level 3, Program terminates
D) Caught in level 1: Error in level 3, Program continues
Question 18 (Flipkart Myntra - 2023)
What does this composition vs inheritance pseudocode demonstrate?
ALGORITHM composition_vs_inheritance
BEGIN
CLASS Engine
horsepower = 0
CONSTRUCTOR Engine(hp)
horsepower = hp
END
FUNCTION start()
RETURN "Engine with " + horsepower + "HP started"
END
END CLASS
CLASS Car
engine = NULL
brand = ""
FUNCTION start_car()
RETURN brand + " car: " + [Link]()
END
END CLASS
ALGORITHM virtual_functions
BEGIN
CLASS Animal
VIRTUAL FUNCTION make_sound()
RETURN "Generic animal sound"
END
FUNCTION describe()
RETURN "This animal makes: " + make_sound()
END
END CLASS
Options: A) This animal makes: Generic animal sound, This animal makes: Woof!, This
animal makes: Meow!
B) All print: This animal makes: Generic animal sound
C) This animal makes: Woof!, This animal makes: Woof!, This animal makes: Woof!
D) Error - virtual functions not supported
Question 20 (InMobi - 2023)
What concept does this template specialization pseudocode show?
ALGORITHM template_specialization
BEGIN
GENERIC CLASS Printer<T>
FUNCTION print(value OF TYPE T)
RETURN "Generic: " + CONVERT_TO_STRING(value)
END
END CLASS
PRINT int_printer.print(42)
PRINT string_printer.print("Hello")
PRINT float_printer.print(3.14)
END