Noise pollution is a significant environmental issue, particularly in industrial settings. The constant hum of machinery, the clanging of metal, and the roar of engines contribute to a cacophony that can have serious health implications for workers and nearby residents. Addressing noise pollution in industries is not only a matter of regulatory compliance but also a crucial step in ensuring the well-being of employees and the community. Understanding Noise Pollution in Industries Industrial noise pollution stems from various sources such as heavy machinery, generators, compressors, and transportation vehicles. Prolonged exposure to high levels of noise can lead to hearing loss, stress, sleep disturbances, and cardiovascular problems. Beyond health impacts, noise pollution can also reduce productivity, increase error rates, and contribute to workplace accidents. Regulatory Framework Many countries have established regulations and standards to limit industrial noise. Organizations like t
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.