Вы находитесь на странице: 1из 6

Subject : Java Programming

Assignment : 10
1. Implement the Inheritance concept as shown in below image.

Hint :-

 Vehicle class properties : idvehicle—id of vehicle , manufacture -- it indicates


company which makes vehicle
 Vehicle class Methods : displayVehicle() -- it displays the vehicle detail
 TransportationVehicle class properties: loadCapacity : -- it indicates load
capacity of vehicle it can carries.
 TransportationVehicle class Methods: displayTransportation()--- it shows
vehicle details along with its loading capacity.
 PassengerVehicle properties : noOfPassengers – it indicates no of passenger it can
carries.
 PassengerVehicle Methods : displayPassenger() - it shows vehicle details along
with no of passenger it can carries.

class vehicle
{
int id_vehicle;
String manufactur;
vehicle(int i, String m)
{
id_vehicle=i;
manufactur=m;
}
void display_vehicle ()
{
System.out.println("Vehicle Id : "+id_vehicle);
System.out.println("Vehicle Company : "+manufactur);
}
}
class transportationVehicle extends vehicle
{
int load_capacity;
transportationVehicle(int id , String man , int load)
{
super(id,man);
load_capacity=load;

186150316006 Page no : 1
Subject : Java Programming
}
void display_transportation()
{
System.out.println("Transportation Vehicle");
display_vehicle();
System.out.println("Load Capacity : "+load_capacity);
}
}
class passengerVehicle extends vehicle
{
int no_passenger;
passengerVehicle(int id, String man,int pas)
{
super(id,man);
no_passenger=pas;
}
void display_passenger()
{
System.out.println("Passenger Vehicle");
display_vehicle();
System.out.println("Number of passenger : "+no_passenger);
}
}
class Personal
{
public static void main(String args[])
{
transportationVehicle t = new transportationVehicle(112233,"TATA",500);
t.display_transportation();
System.out.println();
passengerVehicle p =new passengerVehicle(332211,"BAJAJ",10);
p.display_passenger();
}
}

OUTPUT :

186150316006 Page no : 2
Subject : Java Programming

2. Implement the concept of Method Overriding for below Bank example.


For Bank Example implement the concept of Method Overriding where try to override the
method getRateOfInterest() which will return rate of interest for particular bank.
Example :
SBI : 4.5%
ICICI: 6%
AXIS : 7.5%
abstract class bank
{
abstract float getRateOfInterest();
}
class SBI extends bank
{
float getRateOfInterest()
{
return 4.5f;
}
}
class ICICI extends bank
{
float getRateOfInterest()
{
return 6.0f;
}

186150316006 Page no : 3
Subject : Java Programming
}
class AXIS extends bank
{
float getRateOfInterest()
{
return 7.5f;
}
}
class main
{
public static void main(String args[])
{
SBI s = new SBI();
System.out.println("Rate of Interest in SBI :"+s.getRateOfInterest());
ICICI i = new ICICI();
System.out.println("Rate of Interest in ICICI : "+i.getRateOfInterest());
AXIS a = new AXIS ();
System.out.println("Rate of Interest AXIS : "+a.getRateOfInterest());
}}
OUTPUT :-

3. Make changes in above program to show the use of Dynamic Method dispatch
for above Example.

abstract class bank


{
abstract float getRateOfInterest();
}
class SBI extends bank
{
float getRateOfInterest()
{
return 4.5f;
}

186150316006 Page no : 4
Subject : Java Programming
}
class ICICI extends bank
{
float getRateOfInterest()
{
return 6.0f;
}
}
class AXIS extends bank
{
float getRateOfInterest()
{
return 7.5f;
}
}
class Personal
{
public static void main(String args[])
{
bank s = new SBI();
System.out.println("Rate of Interest in SBI : "+s.getRateOfInterest());
bank i = new ICICI();
System.out.println("Rate of Interest in ICICI : "+i.getRateOfInterest());
bank a = new AXIS ();
System.out.println("Rate of Interest AXIS : "+a.getRateOfInterest());

bank b;
b=s;
System.out.println("Rate of Interest in SBI : "+b.getRateOfInterest());
}
}

OUTPUT :

186150316006 Page no : 5
Subject : Java Programming

4. Implement the concept of inheritance for below example.


interface father
{
void Run_bizznes();
}
interface mother
{
void cooking ();
}
class child implements father, mother
{
public void Run_bizznes()
{
System.out.println("Father run bizznes..");
}
public void cooking ()
{
System.out.println("Mother buzzy in cooking..");
}
}
class main
{
public static void main(String args[])
{
child c = new child ();
c.Run_bizznes();
c.cooking();
}
}

OUTPUT :

186150316006 Page no : 6

Вам также может понравиться