<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nishanth on Medium]]></title>
        <description><![CDATA[Stories by Nishanth on Medium]]></description>
        <link>https://medium.com/@megavathnishanth1312?source=rss-5cf8a5690d8d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AByJNAFiFm3h_ntcHAhpWA.jpeg</url>
            <title>Stories by Nishanth on Medium</title>
            <link>https://medium.com/@megavathnishanth1312?source=rss-5cf8a5690d8d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 21:27:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@megavathnishanth1312/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Object Oriented Programming(OOPS) in C++]]></title>
            <link>https://medium.com/@megavathnishanth1312/object-oriented-programming-oops-in-c-0362240d2692?source=rss-5cf8a5690d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/0362240d2692</guid>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[oops-interview-questions]]></category>
            <dc:creator><![CDATA[Nishanth]]></dc:creator>
            <pubDate>Thu, 26 Jun 2025 17:17:57 GMT</pubDate>
            <atom:updated>2025-06-27T04:11:31.689Z</atom:updated>
            <content:encoded><![CDATA[<p>OOPS is a programming way based on the concept of “<strong><em>objects”</em></strong>, which can contain data(in the form of fields, known as attributes or properties) and code(in the form of procedures, known as methods or member functions).</p><h3>Key Concepts of OOPS:</h3><ol><li>Class</li><li>Object</li><li>Encapsulation</li><li>Inheritance</li><li>Polymorphism</li><li>Abstraction</li></ol><p>The main pillars of OOPS are Encapsulation, Inheritance, Polymorphism, Abstraction.</p><p>Let’s discuss about these concepts.</p><h3><strong>Class:</strong></h3><p>A class is a user defined data type. It contains attributes and methods, which can be accessed and used by creating an instance of class.<br>Class is like a blueprint for an object.</p><h3><strong>Object:</strong></h3><p>An object is an instance of a class. It represents real world entities.<br>When a class is created, no memory is allocated but when it is instantiated(i.e., an object is created) memory is allocated.</p><h3><strong>Access Modifiers:</strong></h3><p>1. Private — data attributes and methods accessible only inside the class.<br>2. Public — data attributes and methods accessible to everyone.<br>3. Protected — data attributes and methods accessible inside the class and to its derived class.</p><p><strong>Note: </strong>By default, everything inside the class is private(i.e., we cannot access data attributes and methods outside the class).</p><h3><strong>Encapsulation:</strong></h3><p>Encapsulation is wrapping up data attributes and methods in a single unit(i.e, class). It is also known as “<strong><em>data hiding</em></strong>”. To hide data, we need to use the <strong><em>private access modifier</em></strong>. The data attributes of a class can be accessed only through member functions of same class in which they are declared.</p><h3><strong>Constructors:</strong></h3><p>Special method invoked automatically at time of object creation. Used for initialisation of objects.<br>Same name as class. Constructor doesn’t have a return type. Only called once(automatically if not defined) at object creation. Memory allocation happens when constructor is called.<br>There are 4types of constructors:<br>1. Non-Parameterized<br>2. Parameterized<br>3. Copy<br>4. Move</p><p><strong>Non-Parameterized Constructor:<br></strong>It is also known as <strong><em>default constructor</em></strong> or <strong><em>zero-argument constructor</em></strong>. It is automatically created by compiler if not defined by programmer.</p><p><strong>Parameterized Constructor:<br></strong>Parameterized constructor allows us to pass arguments to constructors.<br><strong>Note</strong>: If a parameterized constructor is defined, the non-parameterized constructor should also be defined as compiler does not create the default constructor.</p><p><strong>Copy Constructor:<br></strong>Special constructor used to copy properties of one object into another. There are 2 types of copies possible in C++.<br>1. Shallow Copy<br>2. Deep Copy</p><ul><li><strong>Shallow Copy:</strong><br>A shallow copy of an object copies all the member values from one object to another.</li><li><strong>Deep Copy:<br></strong>A deep copy, on the other hand, not only copies the member values but also makes copies of any dynamically allocated memory that the members point to.<br><strong>Note:</strong> A default copy constructor do shallow copy.</li></ul><p><strong>Move Constructor:<br></strong>A move constructor in C++ is a special constructor that transfers (or “moves”) the resources of an value object (temporary object) to a new object, instead of copying them. It helps avoid deep copies and improves performance, especially when working with dynamic memory or large objects.</p><h3><strong>Inheritance:</strong></h3><p>The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is used for code reusability.</p><p>Derived/Child class — The class that inherit methods and properties from the other class and can also have some additional features.</p><p>Base/Parent class — The class that provides common properties and methods which can be inherited by other class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/0*j169r5aDNiNT66Zi.png" /></figure><p>There are 5 types of inheritance which are<br>1. Single<br>2. Multilevel<br>3. Hierarchical<br>4. Multiple<br>5. Hybrid</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*doAQtOVotqeMIck6sxtGsw.png" /></figure><p>Mode of Inheritance:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f789a33cd9eea73118572e7d8885662e/href">https://medium.com/media/f789a33cd9eea73118572e7d8885662e/href</a></iframe><h3><strong>Polymorphism:</strong></h3><p>Polymorphism is the ability of objects to take on different forms or behave in different ways depending on the context in which they are used.<br>There are 2 types of polymorphism:<br>1. Compile-Time polymorphism<br>2. Runtime polymorphism</p><p><strong>Compile-Time Polymorphism:</strong><br>It is also known as <strong><em>early binding</em></strong> and <strong><em>static polymorphism</em></strong>. In this the compiler decides how the function or operator works depend on the context.<br>This polymorphism achieved by <strong><em>function overloading</em></strong> or <strong><em>operator overloading</em></strong>.</p><ul><li><strong>Function Overloading:<br></strong>Function overloading is when we are defining two or more functions with the same name in the class but only differ in terms of their parameters(either by data type or number of parameters).</li><li><strong>Operator Overloading:<br></strong>C++ has the ability to provide the operators with a special meaning for particular data type, this ability is known as operator overloading.<br>For example we can use “+” for addition of integers and also for concatenation of strings.</li></ul><p><strong>Runtime Polymorphism:<br></strong>It is also known as <strong><em>late binding </em></strong>and <strong><em>dynamic polymorphism</em></strong>. The function call in runtime polymorphism, resolved at runtime.<br>This polymorphism achieved by <strong><em>function overriding</em></strong> and <strong><em>virtual functions</em></strong>.</p><ul><li><strong>Function Overriding:<br></strong>Function overriding occurs when derived class has one or more functions of base class. The base class is said to be overridden. The base class function must be declared as <strong><em>virtual function</em></strong> for runtime polymorphism.</li></ul><h3><strong>Abstraction:</strong></h3><p>Hiding all the unnecessary details and showing only the important parts.<br>Abstraction can be implemented using <strong><em>Access Specifiers</em></strong> and <strong><em>Classes</em></strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0362240d2692" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Diamond Problem in OOPS]]></title>
            <link>https://medium.com/@megavathnishanth1312/diamond-problem-in-oops-99d66611735b?source=rss-5cf8a5690d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/99d66611735b</guid>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[oops-interview-questions]]></category>
            <category><![CDATA[oops-in-java]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <dc:creator><![CDATA[Nishanth]]></dc:creator>
            <pubDate>Wed, 25 Jun 2025 09:38:51 GMT</pubDate>
            <atom:updated>2025-06-25T09:38:51.546Z</atom:updated>
            <content:encoded><![CDATA[<p>This Problem arises in <strong>multiple inheritance </strong>and it is an ambiguity error.</p><p>Lets break this problem from the beginning.</p><h3>What is Inheritance?</h3><p>It is a concept where one class(child) inherits the methods and properties from the other class(parent).</p><p>Derived/Child class: The class that inherit methods and properties from the other class and can also have some additional features.</p><p>Base/Parent class: The class that provides common properties and methods which can be inherited by other class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*feUbQiDuskIDBAyXONZDmw.png" /><figcaption>Assuming this is the notation for inherting i.e., Child class inheriting methods and properties from the Parent class.</figcaption></figure><p>There are 5 types of inheritance which are<br>1. Single<br>2. Multilevel<br>3. Hierarchical<br>4. Multiple<br>5. Hybrid</p><p>Talking about <strong>multiple inheritance</strong>, a class will inherit the properties and methods from more than one class.</p><p>Now let’s understand this by taking an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*1OscGwzC7NF2zngqTsI1OA.png" /></figure><p>Here <strong>Parent1</strong> and <strong>Parent2</strong> are inheriting the same method from the <strong>Base</strong> class and <strong>Child </strong>class is inherting same method from both <strong>Parent1</strong> and <strong>Parent2</strong>.</p><p>Lets talk this with respect to programming language C++ and Java.</p><ol><li><strong>C++<br></strong>C++ supports multiple inheritance.</li></ol><p><strong>Example Code:</strong></p><pre>#include&lt;bits/stdc++.h&gt;<br>using namespace std;<br><br>class Base{<br>  public:<br>    void greet(){<br>        cout&lt;&lt;&quot;Hello from Base!!&quot;&lt;&lt;endl;<br>    }<br>};<br><br>class Parent1 : public Base{<br>  public:<br>};<br><br>class Parent2 : public Base{<br>  public:  <br>};<br><br>class Child : public Parent1,Parent2{<br>};<br><br>int main(){<br>    Child c = Child();<br>    c.greet();<br>}</pre><p><strong>Output:</strong></p><pre>main.cpp: In function ‘int main()’:<br>main.cpp:24:7: error: request for member ‘greet’ is ambiguous<br>   24 |     c.greet();<br>      |       ^~~~~<br>main.cpp:6:10: note: candidates are: ‘void Base::greet()’<br>    6 |     void greet(){<br>      |          ^~~~~<br>main.cpp:6:10: note:                 ‘void Base::greet()’</pre><p>Here this ambiguity arises because the child class has multiple paths to access the members or methods inherited from the common ancestor, these leading to confusion during method resoultion and member access.</p><h4>Solution:</h4><p>In C++, we can solve this issue by using V<strong>irtual Inheritance</strong>.<br>Virtual Inheritance ensures <strong>only</strong> <strong>one instance</strong> of a common base class is inherited by all derived classes, preventing ambiguity and redundancy.</p><pre>#include&lt;bits/stdc++.h&gt;<br>using namespace std;<br><br>class Base{<br>  public:<br>    void greet(){<br>        cout&lt;&lt;&quot;Hello from Base!!&quot;&lt;&lt;endl;<br>    }<br>};<br><br>class Parent1 : virtual public Base{<br>  public:<br>};<br><br>class Parent2 : virtual public Base{<br>  public:  <br>};<br><br>class Child : public Parent1,Parent2{<br>};<br><br>int main(){<br>    Child c = Child();<br>    c.greet();<br>}</pre><p><strong>Output:</strong></p><pre>Hello from Base!!</pre><p>2. <strong>Java<br></strong>Java does not supports multiple inheritance.</p><p><strong>Example code:</strong></p><pre>import java.io.*;<br><br>class Base{<br>    void greet(){<br>        System.out.println(&quot;Hello from Base!!&quot;);<br>    }<br>}<br><br>class Parent1 extends Base{<br>    <br>}<br><br>class Parent2 extends Base{<br>    <br>}<br><br>class Child extends Parent1, Parent2{<br>    <br>}<br><br>public class Main{<br>    public static void main(String[] args){<br>        Child c = new Child();<br>        c.greet();<br>    }<br>}</pre><p><strong>Output:</strong></p><pre>Main.java:15: error: &#39;{&#39; expected<br>class Child extends Parent1, Parent2{<br>                           ^<br>1 error</pre><p>Here this error is caused by the multiple inheritance as child class confused from which parent class the <em>greet </em>method should be inherited.</p><p><strong>Solution:<br></strong>In Java, we can solve this issue using <strong>interfaces</strong>. <br>Interface supports multiple inheritance. The purpose of Interface is to describe what should be done.</p><pre>import java.io.*;<br><br>interface Base{<br>    default void greet(){<br>        System.out.println(&quot;Hello from Base!!&quot;);<br>    }<br>}<br><br>interface Parent1 extends Base{<br>    <br>}<br><br>interface Parent2 extends Base{<br>    <br>}<br><br>class child implements Parent1, Parent2{<br>    <br>}<br><br>public class Main{<br>    public static void main(String[] args){<br>        child c = new child();<br>        c.greet();<br>    }<br>}</pre><p><strong>Output:</strong></p><pre>Hello from Base!!</pre><p>By using default void greet() { ... } in the Base interface, we are creating a single, definitive implementation at the very top of the hierarchy.<br>When Parent1 and Parent2 extend Base , they inherit the actual code for it.<br>When the Child class implements both Parent1 and Parent2, the Java compiler needs to decide which greet() method to use.<br>Path 1: Child -&gt; Parent1 -&gt; Base.greet()<br>Path 2: Child -&gt; Parent2 -&gt; Base.greet()</p><p>Both paths leads to the exact same method, there is no ambiguity. The compiler knows which code to use. It’s the one and only default method defined in Base .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99d66611735b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asynchronous and Promises in JavaScript.]]></title>
            <link>https://medium.com/@megavathnishanth1312/asynchronous-and-promises-in-javascript-by-analogy-b1947b9ac4fb?source=rss-5cf8a5690d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1947b9ac4fb</guid>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Nishanth]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 07:57:53 GMT</pubDate>
            <atom:updated>2025-06-24T08:00:23.390Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s imagine you are at a restaurant.</p><p><strong>The Problem: Waiting Around (Synchronous Code)</strong></p><p>Imagine you order food (Task 1), and then you want to get a drink (Task 2).<br>If the restaurant worked “synchronously” (like old-style JavaScript for some tasks):</p><ol><li>You order food.</li><li>You must stand at the counter, doing nothing, until your food is ready.</li><li>Only after you get your food, can you go order and get your drink.<br>This is inefficient! You’re stuck waiting.</li></ol><p>JavaScript, by default, is mostly synchronous for its main operations. If a task takes a long time (like fetching data from a server), your entire webpage would freeze. We don’t want that!</p><p><strong>Solution 1: Callbacks (Callback Hell)</strong></p><p>This is like telling the waiter: “Here’s my food order. When it’s ready, call me back on this number (the callback function), and then I will decide what to do next (like order a drink).”<br>This works, but if you have many dependent tasks, it gets messy: “When the food is ready, call me back. Then, when you call back, I will order a drink. When the drink is ready, call me back again. Then I will ask for the bill…” This leads to<strong> nested functions</strong>, often called “<strong>Callback Hell</strong>,” which is hard to read and manage.</p><p><strong>Solution 2: Promises</strong></p><p>Think of a <strong>Promise</strong> like a restaurant buzzer or a receipt for your order.</p><ol><li>You order food (initiate an asynchronous operation).</li><li>The restaurant gives you a buzzer (a Promise object). This buzzer doesn’t have your food yet, but it’s a <strong>promise </strong>that you will get your food eventually, or they will tell you if there is a problem.</li><li>You can go do other things (your JavaScript continues running other code) while holding onto this buzzer.</li></ol><p>A <strong>Promise </strong>has three states:</p><ul><li><strong>Pending:</strong> You’ve ordered, but the food isn’t ready yet (the operation hasn’t completed).</li><li><strong>Fulfilled:</strong> Your buzzer goes off! Your food is ready (the operation completed successfully, and you have the result).</li><li><strong>Rejected:</strong> The waiter comes and says, “Sorry, we’re out of that item” (the operation failed, and you have an error).</li></ul><p><strong>How to use Promises:</strong></p><p>You attach actions to the promise using <strong>.then()</strong> for success and <strong>.catch()</strong> for failure.</p><p><strong>Solution 3: Async and Await</strong></p><p><strong>async </strong>and <strong>await </strong>are special keywords that make working with <strong>Promises </strong>look more like synchronous code, making it easier to read and write.</p><ul><li><strong>async keyword:</strong> You put async in front of a function declaration. This tells JavaScript two things:<br>1. This function will automatically return a Promise.<br>2. You can use the await keyword inside this function.</li><li><strong>await keyword:</strong> You can only use await <em>inside an </em><em>async function</em>. When you put await in front of a Promise:<br>1. It pauses the execution of the async function <em>at that line</em>.<br>2. It waits for the Promise to settle (either fulfill or reject).<br>3. If the Promise fulfills, await gives you the resolved value.<br>4. If the Promise rejects, await throws an error (just like regular synchronous code would), which you can catch with a try...catch block.</li></ul><h3>Key Takeaways:</h3><ol><li><strong>Promises:</strong> Represent an operation that hasn’t completed yet but will at some point. They help you manage asynchronous tasks without freezing your application or using messy callbacks. Use .then() for success, .catch() for failure.</li><li><strong>async Functions:</strong> Declare a function that handles asynchronous operations. They always return a Promise.</li><li><strong>await Operator:</strong> Used inside async functions to pause execution until a Promise settles. It makes asynchronous code look cleaner and more like synchronous code. You use try...catch for error handling with await.</li></ol><p>Think of async/await as a very polite way of saying &quot;I will wait for this to finish before I do the next step in <em>this specific function</em>, but other parts of my program can keep running.&quot;</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1947b9ac4fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronous VS Asynchronous in JavaScript.]]></title>
            <link>https://medium.com/@megavathnishanth1312/synchronous-vs-asynchronous-in-javascript-by-analogy-a10732cccc17?source=rss-5cf8a5690d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a10732cccc17</guid>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Nishanth]]></dc:creator>
            <pubDate>Mon, 23 Jun 2025 17:20:24 GMT</pubDate>
            <atom:updated>2025-06-24T07:59:58.979Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Synchronous(Sync):</strong></h3><ul><li><strong>Analogy:</strong> You get in line. You order your coffee. You <strong>wait</strong> right there at the counter until your coffee is made. Only after you receive your coffee can the next person in line order and wait.</li><li><strong>In JavaScript:</strong> Code executes line by line, one at a time. Each operation must complete before the next one can start. If an operation takes a long time (e.g., fetching data from a server, reading a large file), the entire program (and in a browser, the user interface) will freeze and become unresponsive until that operation finishes. This is called <strong>blocking</strong>.</li></ul><h3>Asynchronous(Async):</h3><ul><li><strong>Analogy:</strong> You get in line. You order your coffee. They give you a buzzer. You can then go sit down, read a book, or chat with a friend. When your coffee is ready, the buzzer goes off, and you go pick it up. You didn’t have to stand there waiting; you could do other things in the meantime.</li><li><strong>In JavaScript:</strong> When an asynchronous operation is started (e.g., fetching data, setting a timer), the program doesn’t wait for it to complete. It moves on to the next line of code immediately. The long-running task happens in the “background” (managed by the browser’s Web APIs or Node.js’s C++ APIs and the event loop). When the task is finished, a <strong>callback function</strong>, <strong>Promise</strong>, or <strong>async/await</strong> mechanism is used to handle the result. This is <strong>non-blocking</strong>.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e2e874f172c710770c910cc874230c3/href">https://medium.com/media/3e2e874f172c710770c910cc874230c3/href</a></iframe><h3>Why Asynchronous is crucial in JavaScript:</h3><p>JavaScript in browsers (and typically in Node.js) runs on a <strong>single thread</strong>. If everything were synchronous, any long-running operation (like fetching data for a webpage) would freeze the entire browser tab, making for a terrible user experience. Asynchronous operations allow the browser to remain responsive, handling user interactions like clicks and scrolls, while other tasks (like data fetching) are happening in the background.</p><h3><strong>Mechanisms for Handling Asynchronous Operations in JavaScript:</strong></h3><ol><li><strong>Callbacks:</strong> The original way. You pass a function as an argument to another function, and that passed-in function (the callback) gets executed when the async operation completes. Can lead to “callback hell” (deeply nested callbacks).</li><li><strong>Promises:</strong> An object representing the eventual completion (or failure) of an asynchronous operation. They provide a cleaner way to handle async results with .then() for success and .catch() for errors, allowing for better chaining.</li><li><strong>Async/Await:</strong> Syntactic sugar built on top of Promises. It makes asynchronous code look and behave a bit more like synchronous code, making it easier to read and write. The async keyword declares an asynchronous function, and await pauses the execution of that function until a Promise settles.</li></ol><h4>Note:</h4><p><strong>Async </strong>function always returns a <strong>promise</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a10732cccc17" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>