Java Questions 31 - 40  «Prev  Next»

Java Questions regarding Cohesion

  1. What are the benefits of cohesion?

    Answer:
    Benefits of Cohesion. The more focused a class is, the higher its cohesiveness.
    The key benefit to high cohesion is that such classes are typically much easier to maintain.

    Benefits of Cohesion in Software Development

    Cohesion refers to the degree to which the various parts of a module or system work together to achieve a single, well-defined purpose. In software development, achieving high cohesion can have a number of benefits, including: Improved maintainability: Modules with high cohesion are easier to understand and modify, because all the elements within them are related to a single, well-defined purpose. This makes it easier to make changes to the module without causing unintended side effects.
    1. Enhanced reusability: Modules with high cohesion can be more easily reused in other contexts, because they are self-contained and focused on a specific purpose.
    2. Improved reliability: Modules with high cohesion are less likely to contain defects, because they are less complex and have fewer parts that could potentially fail.
    3. Enhanced extensibility: Modules with high cohesion can be more easily extended to support new features or functionality, because they are modular and focused on a specific purpose.
    4. Overall, achieving high cohesion in software development can help make your code more maintainable, reliable, and reusable, which can save time and resources in the long run.
  2. What is meant by cohesive design?

    Answer: Instead of one class that does everything, we break the system into subclasses.
  3. What does cohesion mean in computer programming?

    Answer:
    In computer programming, cohesion refers to the degree to which the elements of a module belong together. Cohesion is a measure of how strongly related each piece of functionality expressed by the source code of a software module is.
    Each subclass has a very specific or cohesive role.
  4. How is the "has-a" concept implemented?

    Answer:
    "has-a" is implemented by using instance variables that refer to other objects.
  5. What is a covariant return type?

    Answer:
    As of Java 5 overriding methods can return a subtype of the declared return type of the superclass.

  6. What does aoverloaded method require?

    Answer:
    An overloaded method requires a change in the argument list.
  7. What are Overloaded methods allowed to vary?

    Answer:
    Overloaded methods are free to vary the 1) return type 2) access modifier 3) declared exceptions
  8. What is the relationship between a class and an interface?

    Answer:
    1) A class can implement more than one interface 2) An interface can extend another interface
  9. What is the difference between inheritance and composition?

    Answer:
    Composition is an object oriented design concept that is closely related to inheritance, as it also deals with reusing classes; but it focuses on establishing HAS-A relationship between classes. So unlike Inheritance, which deals with extending features of a class, composition reuses a class by composing it. Composition is achieved by storing reference of another class as a member.
  10. What is the default constructor?

    Answer:
    The compiler-generated constructor is called the default constructor, and it is always a no-arg constructor with a no-arg call to super().