
Cognizant


Cognizant Software Developer Interview Questions and Answers for Freshers
Q1. Print Name and Age Problem Statement
Create a class named Person
with a string variable 'name'
and an integer variable 'age'
, such that these variables are not accessible outside the class. Implement a method t...read more
Create a class Person with private variables name and age, and methods to set and get their values.
Create a class Person with private variables 'name' and 'age'.
Implement a method setValue to set the variables' values.
Implement a method getValue to print the variables' values.
Ensure the name is a non-empty string and the age is a non-negative integer.
Encapsulate the data and provide a clear interface for setting and getting the values.
Q2. Encode the Message Problem Statement
Given a text message, your task is to return the Run-length Encoding of the given message.
Run-length encoding is a fast and simple method of encoding strings, representing ...read more
Implement a function to encode a text message using run-length encoding.
Iterate through the message and count consecutive characters
Append the character and its count to the encoded message
Handle edge cases like single characters or empty message
Q3. What is the difference between hashtable and hash map
Hashtable is synchronized and does not allow null keys, while hashmap is not synchronized and allows one null key.
Hashtable is synchronized, while hashmap is not.
Hashtable does not allow null keys, while hashmap allows one null key.
Hashtable is thread-safe, while hashmap is not.
Hashtable is slower than hashmap.
Hashtable is part of the legacy collection classes, while hashmap is part of the Java Collections Framework.
Q4. What is virtual function
Virtual function is a function in base class that is overridden in derived class.
Virtual functions allow polymorphism in C++
They are declared using the virtual keyword
They are resolved at runtime based on the object type
Virtual functions can be overridden in derived classes
They are used to achieve runtime polymorphism
Q5. what is array how it is used
An array is a data structure that stores a collection of elements of the same type in a contiguous memory location.
Arrays are used to store multiple values in a single variable.
Elements in an array are accessed by their index, starting from 0.
Example: string[] names = {"Alice", "Bob", "Charlie"};
Arrays can be used to efficiently store and retrieve data in programming.
Arrays can be multidimensional, allowing for more complex data structures.
Q6. what is linklist
A linked list is a data structure that consists of a sequence of elements where each element points to the next element in the sequence.
Each element in a linked list is called a node.
Nodes in a linked list are connected by pointers or references.
Linked lists can be singly linked (each node points to the next node) or doubly linked (each node points to the next and previous nodes).
Q7. what is polymorphism
Polymorphism is the ability of a function or method to behave differently based on the object it is acting upon.
Polymorphism allows objects of different classes to be treated as objects of a common superclass.
There are two types of polymorphism: compile-time (method overloading) and runtime (method overriding).
Example: Inheritance allows a child class to override a method from its parent class, exhibiting polymorphic behavior.
More about working at Cognizant







Top HR Questions asked in Cognizant Software Developer for Freshers
Interview Process at Cognizant Software Developer for Freshers

Top Software Developer Interview Questions from Similar Companies








Reviews
Interviews
Salaries
Users/Month

