What is Aggregation in java? we will discuss Association in Java . Association establishes relationship between two separate classes through their objects . The relationship can be one to one, One to many, many to one and many to many. Association Example class CarClass { String carName ; int carId ; CarClass ( String name , int id ) { this . carName = name ; this . carId = id ; } } class Driver extends CarClass { String driverName ; Driver ( String name , String cname , int cid ){ super ( cname , cid ); this . driverName = name ; } } class TransportCompany { public static void main ( String args []) { Driver obj = new Driver ( "Andy" , "Ford" , 9988 ); System . out . println ( obj . driverName + " is a driver of car Id: " + obj . carId ); } } Output: Andy is a driver of car Id : 9988 In the above example, there is a one to one relationship( Association ...
Comments
Post a Comment