Social Icons

banner image

Nested and Inner classes, Abstract classes and Packages

/*Create a abstract class Vehicle having numberofwheels, sittingcapacity and price as its fields. 4
Derive a  class Car from Vehicle and add modelname and speedlimit details in class Car.
Write appropriate constructors and methods to initialize, modify and display value of attributes.
Modify the above program to create Bike class from Vehicle adding company, mileage and color details
and override the methods (defined in base class) in the derived class.*/



import java.util.Scanner;
public class Vehicle
{
 int n;
 int s;
 int p;
    void getdata()
    {
        Scanner sc =  new Scanner(System.in);
        System.out.println("enter the number of wheels");
        int n1 = sc.nextInt();
          System.out.println("enter the sitting capacity");
        int s1 = sc.nextInt();
          System.out.println("enter the price of the vehicle");
        int p1 = sc.nextInt();
    }
    void display()
    {
        System.out.println("---------------------------");
        System.out.println("wheels pair"+ n);
        System.out.println("sitting capacity : "+s);
        System.out.println("price  :"+p) ;
    }
}
class car extends Vehicle
{
    int m;
    int l;
    void get()
    {
        Scanner sc =  new Scanner(System.in);
        System.out.println("enter the modle number");
        int n1 = sc.nextInt();
          System.out.println("enter the veicle speed limits");
        int s1 = sc.nextInt();
    }
    void disp()
    {
        System.out.println("model number is :  "+m);
        System.out.println("speed limit is : "+l);
    }
class bike extends Vehicle
{
    int  c, mi,cl;
    void get1()
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("enter the bike company");
        int c1= sc.nextInt();
          System.out.println("enter the milegae");
        int mi1= sc.nextInt();
          System.out.println("enter the bike color");
        int cl1= sc.nextInt();
    }
    void disp1()
    {
        System.out.println("bike comapany : "+c);
        System.out.print("mileage of the bike : "+mi);
        System.out.println("enter the bike color : "+cl);
       
    }
}
public class test
{
    private   void  main(String[] args)
    {
        Vehicle v1 = new Vehicle();
        car c1= new car();
        c1.get();
        c1.disp();
   
        v1.getdata();
        v1.display();
        System.out.println("details of the bike");
        bike b1 = new bike();
        b1.get1();
        b1.disp1();
       
    }
}
}
                
Nested and Inner classes, Abstract classes and Packages Nested and Inner classes, Abstract classes and Packages Reviewed by sg on February 14, 2016 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.