Tuesday, 4 August 2015

Java Tutorial : What is a Class?


Click here to watch in Youtube :
https://www.youtube.com/watch?v=JN5WWXDvQdA&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : What is a Class? 

Car.java
/**
 * Car class is the blueprint from which individual car 
 * objects are created.
 */
public class Car
{
    private String brand = null;
    private String model = null;
    private String color = null;

    public String getBrand()
    {
        return brand;
    }

    public void setBrand(String brand)
    {
        this.brand = brand;
    }

    public String getModel()
    {
        return model;
    }

    public void setModel(String model)
    {
        this.model = model;
    }

    public String getColor()
    {
        return color;
    }

    public void setColor(String color)
    {
        this.color = color;
    }

}
CarDemo.java
public class CarDemo
{
    public static void main(String[] args)
    {

        /*
         * Create maruthiAltok10 car object and 
         * set the properties
         */
        Car maruthiAltok10 = new Car();

        maruthiAltok10.setBrand("Maruthi Alto");
        maruthiAltok10.setModel("k10");
        maruthiAltok10.setColor("Orange");

        displayCarInformation(maruthiAltok10);

        /*
         * Create swift car object and 
         * set the properties
         */
        Car swift = new Car();

        swift.setBrand("Swift");
        swift.setModel("ZDI");
        swift.setColor("Red");
        
        displayCarInformation(swift);

        /*
         * Create maruthiAlto800 car object and 
         * set the properties
         */
        Car maruthiAlto800 = new Car();

        maruthiAlto800.setBrand("Maruthi Alto");
        maruthiAlto800.setModel("800");
        maruthiAlto800.setColor("Blue");
        
        displayCarInformation(maruthiAlto800);

    }

    private static void displayCarInformation(Car car)
    {
        System.out.println("Car Brand : " + car.getBrand());
        System.out.println("Car Model : " + car.getModel());
        System.out.println("Car Color : " + car.getColor());
        System.out.println("--------------------------------");
    }

}
Output
Car Brand : Maruthi Alto
Car Model : k10
Car Color : Orange
--------------------------------
Car Brand : Swift
Car Model : ZDI
Car Color : Red
--------------------------------
Car Brand : Maruthi Alto
Car Model : 800
Car Color : Blue
--------------------------------

To Download CarDemoClassApp Project Click the below link
https://sites.google.com/site/javaee4321/java/CarDemoClassApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge