Friday, August 28, 2015

Class n Object

After giving you some information about the basic terms,now its time for some detailed information.
The first and foremost thing you need to remember is that Java is an OBJECT ORIENTED PROGRAMMING LANGUAGE.
Now according to the terms in my previous post, the technical definition of an object is that "It's an instance of class" and that "class is a blueprint from where object is created". Now maybe some of you know these definitions but there are others who may have no idea what am i talking about.
So let me tell you in  a simpler way.

Ok.. just imagine that you need to build a house. Now before building a house..what do you need?
A Map of the house or you may say a blueprint. A blueprint is not the real house but the map of how to make the real house.
Just like this in Java Program, A class is always a blueprint from where we create an object(real thing). Let me give you an example: (just try and practice)
 House.java
public class House     // this is a class called House(Blueprint)
{
String houseaddress;
House(String houseaddress){
this.houseaddress=houseaddress
}
public String getHouseaddress() {
return houseaddress;
}

main.java(the program is executed here)
public class main {
public static void main(String[] args)
{
House object = new House("California");
// whenever 'new' is used just know that a object is created
object.getHouseaddress();

System.out.println(object.getHouseaddress());
}
}





No comments:

Post a Comment