Programming Articles

Page 1476 of 2547

C++ program for Solving Cryptarithmetic Puzzles

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

In the crypt-arithmetic problem, some letters are used to assign digits to it. Like ten different letters are holding digit values from 0 to 9 to perform arithmetic operations correctly. There are two words are given and another word is given as answer of addition for those two words. As an example we can say that two words ‘BASE’ and ‘BALL’, and the result is ‘GAMES’. Now if we try to add BASE and BALL by their symbolic digits, we will get the answer GAMES.NOTE − There must be ten letters maximum, otherwise it cannot be solved.InputThis algorithm will take ...

Read More

Difference between Definition and Declaration in Java.

Nitin Sharma
Nitin Sharma
Updated on 11-Mar-2026 3K+ Views

For the difference between definition and declaration, one should consider their literal meaning first which includes Declare means to announce or proclaim while Define means to describe some entity.The following are the important differences between the Definition and the Declaration.Sr. No.KeyDeclarationDefinition1ConceptThe concept of declaration includes informing the compiler about properties of the variable such as its name, type of value it holds and the initial value if any it takes.While the definition is basically the actual implementation and memory location of function and about memory for the variable is allocated during the definition of the variable.2Exception in CBoth declaration and ...

Read More

Can we synchronize abstract methods in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 1K+ Views

An abstract method is the one that does not have a body. It contains only a method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation (body) to it. If a class contains at least one abstract method, you must declare it abstract.Exampleimport java.io.IOException; abstract class MyClass {    public abstract void display(); } public class AbstractClassExample extends MyClass{    public void display(){       System.out.println("subclass implementation of the display method");    }    public static void main(String args[]) ...

Read More

Can we change the access specifier from (public) while implementing methods from interface in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 737 Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface.To create an object of this type you need to implement this interface, provide a body for all the abstract methods of the interface and obtain the object of the implementing class.All the methods of the interface are public and abstract and, we will define an interface using the interface keyword as shown below −interface MyInterface{    public void display();    public void setName(String ...

Read More

How to hide unsupported interface methods from class in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 1K+ Views

Actually you can’t, once you implement an interface it is a must to provide implementation to all its methods or, make the class abstract. There is no way to skip methods of an interface without implementing (unless they are default methods). Still, if you try to skip implementing methods of an interface a compile-time error would be generated.Exampleinterface MyInterface{    public static int num = 100;    public void sample();    public void getDetails();    public void setNumber(int num);    public void setString(String data); } public class InterfaceExample implements MyInterface{    public static int num = 10000;    public void ...

Read More

What happens if we overload default methods of an interface in java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 2K+ Views

An interface in Java is similar to a class but, it contains only abstract methods and fields which are final and static.Since Java8 static methods and default methods are introduced in interfaces.Default methods − Unlike other abstract methods these are the methods that can have a default implementation. If you have a default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface.In short, you can access the default methods of an interface using the objects of the implementing classes.Exampleinterface MyInterface{    public static int num = 100; ...

Read More

Can we overload methods of an interface in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 8K+ Views

Polymorphism is the ability of an object to perform different actions (or, exhibit different behaviors) based on the context.Overloading is one of the mechanisms to achieve polymorphism where a class contains two methods with the same name and different parameters.Whenever you call this method the method body will be bound with the method call based on the parameters.ExampleIn the following Java program, the Calculator class has two methods with name addition the only difference is that one contains 3 parameters and the other contains 2 parameters.Here, we can call the addition method by passing two integers or three integers. Based ...

Read More

How to override only few methods of interface in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 8K+ Views

Once you implement an interface from a concrete class you need to provide implementation to all its methods. If you try to skip implementing methods of an interface at compile time an error would be generated.Exampleinterface MyInterface{    public void sample();    public void display(); } public class InterfaceExample implements MyInterface{    public void sample(){       System.out.println("Implementation of the sample method");    }    public static void main(String args[]) {       InterfaceExample obj = new InterfaceExample();       obj.sample();    } }Compile-time errorInterfaceExample.java:5: error: InterfaceExample is not abstract and does not override abstract method display() ...

Read More

Is parent child hierarchy important on throws while overriding in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 401 Views

When you try to handle an exception (checked) thrown by a particular method, you need to catch it using the Exception class or super class of the Exception occurred.In the same way while overriding the method of a super class, if it throws an exception −The method in the sub-class should throw the same exception or its sub type.The method in the sub-class should not throw its super type.You can override it without throwing any exception.When you have three classes named Demo, SuperTest and, Super in (hierarchical) inheritance, if Demo and SuperTest have a method named sample().Exampleclass Demo {   ...

Read More

Maximum length subarray with LCM equal to product in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 430 Views

Suppose we have an array A. We have to find the maximum length of the subarray, whose LCM is the same as the product of the elements of that subarray. If that kind of subarray is not found, then return -1. Suppose array is {6, 10, 21}, then the length is 2, as the subarray {10, 21} is there, whose LCM is 210, and the product is also 210.The approach is straight forward. We have to check every possible subarray of length greater or equals to 2. If the subarray is satisfying the condition, then update the answer as a ...

Read More
Showing 14751–14760 of 25,466 articles
Advertisements