IS-A RELATIONSHIP ================= class ClassA{ } class ClassB extends ClassA{ } ClassB Is-A ClassA HAS-A RELATIONSHIP ================== class ClassA{ // dependent } class ClassB{ // dependency ClassB(){ ClassA aobj = new ClassA();// instance of ClassA } } ClassB HAS-A ClassA class ClassC{ ClassC(){ ClassB bobj = new ClassB(); } } ==> When we can define an instance of one class in another class, then we can call the relation between these two classes as "Has-A Relationship". ==> From the above example, we have created an instance of ClassA in ClassB So, ClassA ==> Dependent ClassB ==> Dependency ==> Has-A relationship can be in two ways: 1) Composition 2) Aggregation 1) Composition ============== class Person{ class PassPort{ Person() } { passport = new PassPort(); } } class Mobile{ class Sim{ Mobile() } { sim = new Sim(); } } The strong bonding between dependent and dependency is called as "composition". Here, the dependency cannot perform anything without dependent. 2) Aggregation ============== class PolicyHolder{ // dependent } class Policy{// dependency Policy() { policyholder = new PolicyHolder(); } } ==> the bonding between dependent and dependency is weak and the dependency can perform anything without dependent. ========================================================= FINAL ===== ==> final ==> finalized/fixed ==> final elements can define for only one time and not allowed for change/modification. ==> can define with: variables ==> final variables methods ==> final methods classes ==> final classes final variables: ================ ==> final variables ==> constants two types of constants: 1) Class Level Constants 2) Object Level Constants 1) Class Level Constants ========================= class TimeInHours{ static final HOURS_PER_DAY = 24; } per1 per2 2) Object Level Constants ========================== class BankAccount{ private final accountNumber; private balance; } ==> Final variables we can initialize in constructor. class BankAccount{ private final accountNumber = 1212; private balance; public BankAccount(accountNumber, balance) { this.accountNumber = accountNumber; this.balance = balance; } } ==> for final variables, we cannot generate setter method but we can generate getter method. Because, setter method can change the value but getter method can return the value. ================ final methods ============== ==> when we want to create a method with fixed implementation and cannot be overridden, then we can create that method as "final". ==> final methods cannot be override. ==> final methods can overload within the class but not in child class. package Pack.IO.AIT; class A{ public final void m1() { System.out.println("Hi"); } public final void m1(int x) { System.out.println("Hi"); } } class B extends A{ @Override public void m1() { System.out.println("Hi"); } public final void m1(int x) { System.out.println("Hi"); } } public class Main { public static void main(String[] args) { // TODO Auto-generated method stub } } =================================== final class: ============