Java Lession-3
Class : A Class is a collection of fields(variables) and methods (functions)
Object : Object is instance of class and using object the fields and methods are
accessed.
Ex:
Class Car
{
////fields in the class
String name,color,model;
int price
///method
public void Drive()
{
System.out.println("Driving");
}
public static void main(String args[])
{
///create object for the class , using obj access the fields and methods
Car honda=new Car();
honda.name="Honda CRV";
honda.color="blue";
honda.model="SUV-4";
honda.price=13
honda.Drive();
}
}
Class : A Class is a collection of fields(variables) and methods (functions)
Object : Object is instance of class and using object the fields and methods are
accessed.
Ex:
Class Car
{
////fields in the class
String name,color,model;
int price
///method
public void Drive()
{
System.out.println("Driving");
}
public static void main(String args[])
{
///create object for the class , using obj access the fields and methods
Car honda=new Car();
honda.name="Honda CRV";
honda.color="blue";
honda.model="SUV-4";
honda.price=13
honda.Drive();
}
}
Comments
Post a Comment