Join Regular Classroom : Visit ClassroomTech

Lexmark International Overall Interview Questions + Coding Solutions – codewindow.in

Hot Topics

Lexmark International Solution

Technical Round

Questions like virtual function, friend function, virtual destructors.

  • Virtual functions:
    Virtual functions are member functions in a base class that can be overridden by derived classes. They are typically used to provide a common interface for different types of objects, while allowing each derived class to implement the function in its own way.
  • friend function:
    A friend function is a non-member function that has been granted access to the private and protected members of a class. This is done by using the keyword “friend” before the function declaration.
  • Virtual destructor:
    Virtual destructors are destructors that are declared as virtual in a base class. When a derived class object is deleted through a pointer or reference to the base class, the derived class destructor is called, even if the destructor is not virtual. This is important to avoid memory leaks and to ensure proper cleanup of derived class resources.

Why manholes are round?

Manholes are typically round because a round shape is the most efficient and practical shape for the purpose of providing access to underground utility lines.

Write a solution using data structure and OOPs concept.

One example of a solution using data structures and OOP concepts could be a program for managing a library’s inventory. The program could include classes for representing books, patrons, and loans.
The Book class would have properties such as title, author, ISBN, and number of copies. The class would also include methods for checking out and returning a book, as well as for checking the availability of a book.
The Patron class would have properties such as name, address, and library card number.
The Loan class would have properties such as the book being borrowed, the patron borrowing the book, and the due date of the loan.
 A hash table could be used to quickly look up a patron or a book by their unique identifier.

How is polymorphism/ runtime binding is actually implemented?

Polymorphism and runtime binding are implemented using a mechanism called virtual function table (VTABLE) or virtual method table (VMT) in C++.
When a class contains virtual functions, the compiler creates a virtual function table (VTABLE) for that class. The VTABLE is an array of function pointers that point to the implementation of the virtual functions for that class. Each class that inherits from that base class will have its own VTABLE that overrides the virtual functions as necessary.
When an object is created, the memory layout of the object contains a pointer to the VTABLE of the class that the object belongs to. This pointer is known as the virtual pointer (VPTR) and it points to the start of the VTABLE of the class.
When a virtual function is called on an object, the program looks up the function pointer in the VTABLE using the VPTR, and then calls the function through that pointer. Because the VPTR points to the VTABLE of the object’s class, the correct version of the virtual function will be called at runtime, even if the object’s type is not known at compile-time. This mechanism is known as runtime binding or dynamic binding.
It’s worth mentioning that the above explanation is based on the C++ programming language, other programming languages may implement the polymorphism and runtime binding differently. In some languages like Java, polymorphism is implemented using method overriding and dynamic method dispatch, in this case, the Java Virtual Machine (JVM) performs the lookup of the correct method to call at runtime.

How to multiply a number if the processor do not have multiplication hardware?

There are a few ways to perform multiplication on a processor that does not have multiplication hardware.
i)Using repeated addition,ii)Using bit shifting,iii)Using the Russian Peasant Multiplication Algorithm,iv)Using a lookup table

Difference between list and set.

List
Set
1.    List stores duplicate elements.
Set does not store duplicate elements.
2.    Elements is list can be accessed using their position.
Elements in set cannot be accessed using their position.
3.    List is sequentially indexed.
Set is sequentially non-indexed.
4.    Multiple null elements can be stored.
Null elements can store only once.
5.    E.g. ArrayList, LinkedList
E.g. HashSet, LinkedHashSet
 

What are the examples of functional programming language?

Examples of functional programming language are JavaScript, Python, Scala, etc.

Write a class named Document to represent a document node in a print queue. it should contain a method name that returns the subject of the document and an abstract method called type that returns the document type . from document class derive two concrete classes named word document and pdf document

class Document:
    def __init__(self, subject):
        self.subject = subject

    def name(self):
        return self.subject
    
    def type(self):
        raise NotImplementedError("Subclass must implement abstract method")

class WordDocument(Document):
    def type(self):
        return "Word Document"

class PDFDocument(Document):
    def type(self):
        return "PDF Document"

Write another class named Print Queue that is implemented as a linked list of Document objects. Print Queue should have a method named Push for adding a document to the end of the list, a method named pop for removing the first document from the list , and a method named DisplayContents for listing all of the documents in the Print Queue, reporting both the Name and Type of each element Print Queue should not use any standard library classes it should be own implementation of linked list

class Node:
    def __init__(self, document, next=None):
        self.document = document
        self.next = next

class PrintQueue:
    def __init__(self):
        self.head = None
        self.tail = None

    def push(self, document):
        if self.head is None:
            self.head = Node(document)
            self.tail = self.head
        else:
            self.tail.next = Node(document)
            self.tail = self.tail.next

    def pop(self):
        if self.head is None:
            return None
        else:
            document = self.head.document
            self.head = self.head.next
            if self.head is None:
                self.tail = None
            return document

    def display_contents(self):
        current = self.head
        while current is not None:
            print("Name: ", current.document.name())
            print("Type: ", current.document.type())
            current = current.next
What’s the difference between C/C++ and Java?
C++
Java
1.    C++ is a platform dependent language.
Java is a platform independent language.
2.    C++ supports multiple inheritance.
Java does not support multiple inheritance but it can be achieved using interfaces. 
3.    C++ supports operator overloading.
Java does not support operator overloading.
4.    C++ supports go to statement.
Java does not support go to statement.
5.    We have both call by value and call by reference in C++.
Java does not support call by reference but supports call by value.
 

What is dynamic memory allocation? Where does the memory gets allocated when you use malloc or calloc?

Dynamic memory allocation is the process by which memory space is assigned during execution time or runtime.
 When we use malloc or calloc heap memory is allocated during runtime.

Difference between for loop and while loop?

For loop
While loop
1.    A for loop is more efficient loop structure in C programming.
A while loop is the most straight forward loop structure.
2.    General syntax:
1.     for(initialization; condition; increment/decrement){
2.     statement;
3.     }
while(condition){
statement;
}
3.    Example:
1.     int main(){
2.     int i;
3.     for(i=1; i<=3; i++){
4.     printf(“%d”,i);
5.     }
6.     return 0;
7.     }
Example:
int main(){
int n;
while(n<=3){
printf(“%d”,n);
n++;
}
return 0;
}
 

Nagarro Solved

Automata Fixing

      

We Love to Support you

Go through our study material. Your Job is awaiting.

Recent Posts
Categories