How to “return an object” in C++?

Ravi Ranjan
Updated on 20-May-2025 19:38:05

5K+ Views

An object is an instance of a class. The memory is allocated only when an object is created and not when a class is defined. How to Return an Object in C++? An object can be returned by a function using the return keyword. There is no specific technique to return an object, you can simply return it just like any other data type returning from the function. Consider the following syntax. Syntax The syntax for returning an object from the function is as follows: class_name function_name(class_name obj1) // Passing object { class_name obj2; ... Read More

What is a virtual base class in C++?

Aman Kumar
Updated on 20-May-2025 19:30:46

2K+ Views

Virtual Base ClassVirtual base classes are used in virtual inheritance. It is a way of preventing multiple instances of given classes occurs in the inheritance hierarchy when using multiple inheritance. Why We Use Virtual Base Class? The use of a virtual base class ensures that only one shared instance exists in memory. Virtual base class prevents duplicate base class copies in multiple inheritance. Virtual base classes provide efficient memory management. It avoids redundant copy of base class variables. It ... Read More

Can we declare more than one class in a single Java program?\

Shriansh Kumar
Updated on 20-May-2025 19:30:19

17K+ Views

Declaring Multiple Classes in Java Program A single Java program may contain two or more classes, it is possible in two ways: Multiple non-nested classes Nested classes The Multiple non-nested Classes We can create as many classes as we want in a single Java program but writing many classes in a single file is not recommended as it makes code difficult to read rather we can create a single file for every class. When we compile a Java program with two or more classes (non-nested), the same number of .class ... Read More

Can a C++ virtual functions have default parameters?

Aman Kumar
Updated on 20-May-2025 19:29:14

843 Views

Yes, C++ virtual functions can have default parameters. The default parameter is the value provided during function declaration, such that the value can be automatically assigned if no argument is passed to them. In case any value is passed the default value is overridden and becomes a parameterized argument. Virtual Function A virtual function is a member function declared in a base class and can be overridden in a derived class. When we use a pointer or reference to the base class to refer to an object of the derived class, you can call a virtual function for that object. ... Read More

What are the differences between compareTo() and compare() methods in Java?\

Shriansh Kumar
Updated on 20-May-2025 19:28:58

9K+ Views

The compareTo() and compare() methods are both used to compare two objects. They return an int value after comparison, which tells if both objects are equal, if not, which is lesser, and which is greater. The primary difference between these two methods is that the compareTo() method is used when the Comparable interface is implemented, whereas the compare() method is used when the Comparator interface is implemented. Let's understand the use of compareTo() and compare() methods in Java, and then we will discuss how these two methods are different from each other. The compareTo() Method in Java The compareTo() method compares the ... Read More

C++ Program to Implement Bitap Algorithm for String Matching

Aman Kumar
Updated on 20-May-2025 19:24:35

503 Views

The bitap algorithm is fuzzy string matching algorithm that is used to find approximate matches between a pattern and a text. The algorithm determines whether a given text contains a substring that is "approximately equal" to a given pattern, where approximate equality is defined in terms of Levenshtein distance (or number of edits) if the substring and pattern are within a given distance k of each other, then according to the algorithm they are equal. It begins by precomputing a set of bitmasks containing one bit for each element of the pattern. So we can do most of the work with ... Read More

What are unreachable catch blocks in Java?

Shriansh Kumar
Updated on 20-May-2025 19:24:08

6K+ Views

A block of statements that the program control can never reach under any circumstances can be called an unreachable block. Java does not support unreachable blocks, such code will cause a compile-time error. Any code that is written but never executed is considered unnecessary by the Java compiler. In this article, we will discuss unreachable catch blocks in Java. But, before that, let's understand what is a catch-block in Java. The catch Block in Java The catch block is written just after the try block and cannot have any code between them. It is an exception handler and contains code ... Read More

Why Char[] array is more secure (store sensitive data) than String in Java?

Shriansh Kumar
Updated on 20-May-2025 19:16:27

5K+ Views

Both String class and Char[] array in Java are used to store textual data. However, Strings are immutable, which means you can't make changes to a String once defined, and the char[] array is not immutable. In the official documentation of Java Cryptography Architecture, it is clearly written that String objects are not suitable for storing sensitive data, such as passwords, SSN, etc. Use a char array instead, as it is more secure than String. This article will help you understand why char[] array is used to store sensitive data. Char Array is more secure than String Let's discuss why ... Read More

Importance of @JsonFilter annotation in Java?

Manisha Chand
Updated on 20-May-2025 19:02:42

1K+ Views

The @JsonFilter annotation belongs to Jackson Annotations. Jackson Annotations are used during serialization and deserialization to denote a particular field (or method) that is declared in Java as an instance variable, is a JsonProperty, and should be ignored, or what condition should be applied to it. It is used to define a dynamic filter for serializing/deserializing Java objects. @jsonfilter annotation Let's discuss the importance of jsonfilter annotation as given below - It is used to filter which fields or properties of an object should be included ... Read More

C++ Program to Implement the String Search Algorithm for Short Text Sizes

Aman Kumar
Updated on 20-May-2025 18:50:55

460 Views

Searching for a substring within a short text is a common operation in many C++ programs, like as small-scale text editors, command line utilities, and education projects. So, in this article, we will implement a string search algorithm for short text sizes. Importance of String Search String search algorithms find a substring within another string. While advanced methods like KMP and Boyer-Moore are great for longer texts, a simple method like Naive search works well for short texts without added complexity. Algorithm to Implement String Search Algorithm for Short Text Sizes The Following is a string search algorithm − Begin ... Read More

Advertisements