Vous êtes sur la page 1sur 2

Polymorphism (Many form): Two ways by which polymorphism can be achieved are: Method Overloading : More than one

method in a same class with same name but different parameter. Method Overriding: Redefinition of a method inherited from super class. Once method is declared final, it cant be overridden. Static (Global variable, method or class): Also called class variable or method. Variable or method that are stored in a class rather than on the instance of a class. Facts: Any changes made to a static variable or method by an object (instance) is made to all other instances of a class.

We can call class method or class variable by using the class name without having to create an
instance of class.

For e.g. BankAccount.setInterestRate(5); Static variable or method is initialized when class is loaded in the JVM and are loaded before main()
method.

When Java Application loads there is no object, so we use static keyword in front of main()
method so that JVM invokes it when application is launched. A static method cannot access non-static variables and methods of a class. Constant: A variable whose value remains same throughout the execution of application. In java constant is defined using final keyword. For e.g. private final int VAT = 20%; //instance specific constant (less common !) private static final int VAT = 20%; //constant applies to all instances of a class. Constructor Method: Method that execute automatically when object is created Worker Method: Method with private assessor as it is only uses by other method within same class. Abstract class (Incomplete class): Class from which an instance cannot be created. It is simply used for the purpose of inheritance. Interface Class: Class in which all the methods are abstract and the implementing subclass inherits all the abstract methods and have to provide its own implementation. Information Hiding: Two aspects

i) ii)

Users of other class need not to know. User of class should not be allowed to know

Encapsulation (Hiding of data): It is a concept where the attribute is made private and access to it is made by public getter and setter method. Benefits:

If an attribute of a class is made public, number of possibility of operations is large leading to a security
issues. Prevent code from being randomly accessed by other class. Field can be made read or write only Inheritance: Sharing of attributes and methods among classes. Association: Relationship between instances of class. Multiplicity: Association also has multiplicity which means how many objects participate in a given relationship. Aggregation: is a part of relationship Composition: Stronger form of aggregation in which object belong to only one whole. Therefore, deleting of whole will delete a part. For e.g. If customer object is deleted the order object will also be deleted. Coupling: interconnectedness between classes Tight Coupling: Changes in one class requires changes to be made in subsequent class. Disadv: change on one class can ripple throughout the application difficult and time consuming to find the classes where changes need to be made c) introduce further error Weak Coupling: Changes in one class does not require changes to be made in another class. Cohesion: One unit of code (method, class, module) responsible for one and only one task Highly Cohesion: one unit of code that is responsible for a well defined task. For e.g. Employee class should contain properties and method that describes state and behaviour of an employee and not a department of an employee. Adv: Readability and Reusability Good Design = highly cohesive and weakly coupled Refactoring: Restructuring of a class by breaking (sometime even joining) classes and methods as it grows larger. It involves rethinking and redesigning of a class.

Message Passing: process by which one object use another objects method.

a) b)

Object has set of attributes that define, store and preserve its state. Attribute is also called instance variable or class variable and resided in the Heap Memory. Instance Variable or Class Variable are stored in a heap memory

Object methods (getter and setter) are used to access and modify its state. Local Variable or Field Variable or Method Variable or Stack Variable (because stored in Stack Memory) is used inside the method and their lifetime is limited (i.e. exist in a memory) to the duration of the method.

Vous aimerez peut-être aussi