Quantum Computing – The Next Tech Revolution Technology has evolved rapidly over the last few decades—from bulky mainframe computers to powerful smartphones in our pockets. Yet, despite these advances, traditional computers are approaching their physical limits. This is where quantum computing enters the scene, promising to revolutionize the way we process information and solve complex problems. What Is Quantum Computing? Quantum computing is a new paradigm of computing that uses the principles of quantum mechanics, a branch of physics that explains how matter and energy behave at the smallest scales. Unlike classical computers, which use bits that represent either 0 or 1, quantum computers use qubits. Qubits can exist in multiple states simultaneously, thanks to a property called superposition. Additionally, qubits can be interconnected through entanglement, allowing them to share information instantaneously. These unique properties give quantum computers immense computational power....
Q) What is composition in Java ?
Composition is the design technique to implement has a relationship in classes. We can use object composition for code reuse.
Java composition is achieved by using instance variables that refer to other objects. The benefit of using composition is that we can control the visibility of other objects to client classes and reuse only what we need.
Q) What is the benefits of composition over inheritance ?
Prefer composition over inheritance is a one of the popular object oriented design principles, some of the possible reasons are
1) Inheritance is tightly coupled whereas composition is loosely coupled.
2) Any change in superclass might affect subclass even though we might not be using the superclass methods. For example, if we have a method test() in the subclass and suddenly somebody introduces a method test() in the superclass, we may get compilation errors in the subclass. Composition will never face this issue because we are using only what methods we need.
3) Inheritance expose all the superclass methods and variables to the client and if we have no control in designing superclass, it can lead to security holes. Composition allows us to provide restricted access to the methods and hence more secure.
4) One more benefit of composition over inheritance is testing scope. Unit test is easy in composition because we know what all methods we are using from other class. We can mock it up for testing whereas in inheritance we depend heavily on superclass and don't know what all methods of superclass will be used. So we will have to test all the methods of superclass. This is an extra work and we need to do it unnecessarily because of inheritance.
Q) What does super keyword do ?
super keyword can be used to access super class method when you have overridden the method in the child class.
We can use super keyword to invoke superclass constructor in child class constructor but in that case, it should be the first statement in the constructor method.