Difference Between a Virtual Function and a Pure Virtual Function in C++

Aman Kumar
Updated on 18-Jun-2025 18:40:06

7K+ Views

In C++, virtual and pure virtual functions are key features supporting polymorphism both allow different classes to respond uniquely to the same function call. What is Virtual Function A virtual function in C++ is a member function in a base class, which allows a function to be overridden in the derived class. This process helps in enabling runtime polymorphism. A virtual function is declared in the base class using the virtual keyword. Syntax Following is the syntax of the virtual function: class BaseClassName { public: virtual void func_name() { // implementation ... Read More

Return Multiple Values from a Function in C/C++

Aman Kumar
Updated on 18-Jun-2025 18:38:24

28K+ Views

In C or C++, we cannot return multiple values from a function directly. In this Article, we will see how to use some trick to return more than one value from a function. Returning Multiple Values from a Function We can return multiple values from a function by using the method. Below is the list of methods that are used to return multiple values from a function in C/C++: Using Pointers Using Structures Using Arrays Returning Multiple Values Using Pointers Pass the arguments by their addresses ... Read More

C++ Conversion Operators Guide

Aman Kumar
Updated on 18-Jun-2025 18:35:59

2K+ Views

What is Conversion Operator Conversion operators are a type of operator overloading in C++. These operators are commonly known as type-cast operators. They enable a class or structure to specify how an object should be converted into another data type. Sometimes we need to convert concrete-type objects to some other type of objects or primitive data types. To make this conversion we can use a conversion operator. Following is the syntax to use the conversion: class ClassName { public: operator TargetType() const { // conversion logic } }; ... Read More

Placement New Operator in C++

Aman Kumar
Updated on 18-Jun-2025 18:33:22

2K+ Views

In C++, we allocate the memory dynamically using the new operator. But there is a special version of this operator known as placement new operator. The new operator performs two things. It allocates memory, and then constructs an object in allocated memory. But for the placement new operator, it constructs object at the given address. What is Placement New? The placement new operator allows you to construct an object at a specific memory location. Its syntax lets you place an object at a pre-allocated memory address instead of letting the compiler allocate memory. new (address) Type (constructor_args); Where ... Read More

Heap Overflow and Stack Overflow Explained

Aman Kumar
Updated on 18-Jun-2025 18:31:25

651 Views

Heap and stack overflows are both types of buffer overflows that occur when a program attempts to write data beyond the allocated boundary of a buffer. Heap Overflow Heap is used to store dynamic variables. It is a region of process’s memory. malloc(), calloc(), resize() all these inbuilt functions are generally used to store dynamic variables. Following are the regions where heap overflow occurs − If we allocate dynamic large number of variables int main() { float *ptr = (int *)malloc(sizeof(float)*1000000.0)); } If we continuously allocate memory and do not free after using it. int main() { for (int i=0; i

Generate UnsupportedOperationException in Java

Vivek Verma
Updated on 18-Jun-2025 18:31:11

492 Views

In Java, an exception is an event that occurs during the execution of a program. When an Exception occurs, the normal flow of the program is disrupted, and the program/application terminates abnormally, which is not recommended; therefore, these exceptions can be handled. What is UnsupportedOperationException in Java? An UnsupportedOperationException is a subclass of the RuntimException class in Java, and it can be thrown to indicate that the requested operation is not supported. The UnsupportedOperationException class is a member of the Java Collections Framework. This exception is thrown by almost all of the concrete collections like List, Queue, Set, and Map. ... Read More

Uses of Generic Collections in Java

Vivek Verma
Updated on 18-Jun-2025 18:30:32

7K+ Views

What are Generic Collections in Java? In Java, the Generic collections were introduced in Java 5. These collections disable the type-casting, and there is no need for explicit type-casting if we use generic collections. The generic collections are type-safe and detect type-related errors at compile time. It allows the datatypes to pass as parameters to classes or interfaces. The Compiler is responsible for checking the compatibility of the types. Syntax Following is the way to create generic collections in Java: class or interface Where type specifies the type of the object, such as: Integer, String, Character, etc.. You can create generic ... Read More

Differences Between Collection and Collections in Java

Vivek Verma
Updated on 18-Jun-2025 18:25:58

9K+ Views

In Java, Collection and Collections are important components of the Collections Framework. The Collection has various sub-interfaces such as Set, List, and Queue. The Collections provides static methods to perform various operations on collections, such as sorting, searching, and synchronization. Let's learn them one by one with proper definitions, syntax, and a suitable example. The Collection Interface In Java, the Collection is an interface, which is considered the root interface in the collection hierarchy. It represents a group of objects, which are known as its elements. Some collections allow duplicate values and specific orders, whereas some do not allow duplicates ... Read More

Importance of @Override Annotation in Java

Vivek Verma
Updated on 18-Jun-2025 18:25:31

10K+ Views

What is an Annotation? An annotation is like metadata that provides additional information about the code. It does not affect the code directly but provides the information so that the compiler or runtime environment can use it while executing the code. To define or use any annotation in Java, you need to specify the annotation name starting with the "@" symbol. Here is the syntax to use annotations in Java: @annotation_name Where the @ symbol specifies the annotation, and annotation_name is the name of the annotation. Following is a list of a few important annotations and their usage: ... Read More

Read Number from Standard Input in Java

Manisha Chand
Updated on 18-Jun-2025 18:17:59

2K+ Views

In Java, to read input from standard input(via keyboard), Java provides a built-in Scanner Class. In this article, we will understand how to read a number from standard input(via keyboard) in Java. The Scanner.nextInt() method of the Scanner class belongs to java.util package is used to read the number. The java.util.Scanner.nextInt() method scans the next token of the input as an int. The nextInt() method reads numbers in base-10 (decimal numbers) by default. To read numbers in other bases, like binary or hexadecimal, you can use nextInt(radix). Problem Statement Write a Java program to read a number from standard input. ... Read More

Advertisements