What is benefits of constructor overloading in c++ -Real Time Example

Benefits of constructor overloading in c++ interview question – We need to answer why constructor overloading is required in C++ program? and what are advantages of it? and also, with real time example from your project. Answer: Benefits of constructor overloading in C++ is that, it gives the flexibility of creating multiple type of objects…

Read the full article

What is friend class in C++? Show by C++ Code example

Answer includes friend class in C++ using a C++ code example and uses. Rather that defining it lets describe friend class by example and understand definition.. Answer: Mainly, friend class is used for encapsulation (data hiding). If we want some class to keep private variables/data visible to some specific class and don’t want it to…

Read the full article

C++ self-assignment -If object assigned to itself what happens

Answer: Self assignment of object in C++ is OK only if object declaration and initialization has been already done before. Otherwise, we may get compiler error for object declaration or run time crash, stating object has not been initialized. In below complete example, in class A, we have declared an object int Id and has…

Read the full article

Implement an objects counter mechanism for a class in C++

Interview question: Can you implement an object counter program in C++ for a class that count the number of objects created for that class. Answer: Actually, counting object in C++ implementation is simple. Solution is, to create a static variable, say “objCount” and a static method like “GetObjectCount()” that returns number of objects created for…

Read the full article

Callable Vs Runnable interface in Java multithreading?

Callable Vs Runnable interface in Java Multithreading. A Callable can return a result but a Runnable interface cannot. A Callable can throw checked exception but a Runnable cannot. Callable provides call() method to implement and Runnable interface provides run() method to implement in java. Here is the example how callable and runnable interface look like.…

Read the full article

Can we override start method of thread class in java?

Answer: Yes, we can override start() method of thread in Java, the same way we override any other methods. for example, In below, custom thread class MyThread, both start() method and run() method have been overridden. When we create an object of custom thread and call start() method, run() will be automatically called. You may…

Read the full article

what is minimum thread priority in java thread programming?

The minimum thread priority in java is 1 and maximum or highest thread priority is 10. We will see a program example to set and get thread priority. Default priority of thread in java is = 5. Minimum thread Priority = 1 Maximum thread Priority = 10 We can set priority of a thread within…

Read the full article

What is difference between pre-emptive scheduling and non-pre-emptive scheduling?

Answer: Pre-emptive scheduling: In this scheduling the highest priority thread runs when it has a chance to do so. This means that an executing lower-priority thread must yield the CPU to a thread with a higher priority that is ready to run. Non-pre-emptive Scheduling: This scheduling is based on the order of the threads waiting…

Read the full article

What thread-scheduling algorithm is used in Java?

Answer: There are two algorithms, used for Java thread scheduling. Time sliced also known as Round-Robine algorithm. Pre-emptive scheduling.   Java uses different scheduling algorithm on different platforms e.g. On Mac – time-sliced On Solaries – pre-emptive On Windows- pre-emptive before JDK-1.0.2, after it is time-sliced.   Notes: Thread scheduling algorithms are platform dependent and…

Read the full article

Does each thread have its own copy of JVM instance?

Answer: No, by definitions threads in a Java application share the same memory space, therefore, they are executing within the same JVM. This way you can easily share objects across multiple threads, perform synchronization and such, all that is happening within the JVM. One way to see it is that processes have their own memory…

Read the full article