What are classes and objects in java.
20-05-2017    383 times
java class object

Objects are the real entity in the world and class is the framework of objects. Therefore we can say classes and objects are interrelated topic in real life and java. Any member of the class can access by the objects of that class. only static member of the function can access through the class name.Static variable are known as class variable and a non-static variables known as object variables.

What is object?

Any real entity of the world which has its own unique characteristic, state and behavior are called an object.

Ex. a Pen, a ball, you, me, a cat, a chair, a TV etc.

Examples of Objects
Examples of Objects

What is class?

Class is a collection of same types of objects. We can declare a class by the keyword class.

Tutorial at home

Ex. All of us are belongs to the Human class. In other words any objects of the Human class are refer a person of the world.

Java class consist two parts

  1. Member variables: These variables are holds the value which determine the state and behavior of the class objects.
  2. Member function or method: These methods are used to control the member variable and perform different logics.

Note : Every Java Program should write with in a class. And we can access the member variable and member function by using the object of that class.

Procedure of writing class name

  1. Class name always start with alphabet.
  2. No Special character allowed.
  3. If class name is in one word the first character must be capital and others letter must be small. Let the class name is draw, then it should be write as Draw not draw.
  4. If class name have multi word then first character of each word should be Capital and no space allowed in between the words. Let the class name is draw line, then it should be write as DrawLine not Draw Line or Drawline.
Tutorial at home

Program Example

Here we create a class called Human. And also we create the object of that class from another class called AccessHuman

class Human
{
private int age,height;
public void setValues(int a,int h);
{
age=a;
height=h;
}
public void getValues()
{
System.out.println(“Your Age is “ + age);
System.out.println(“Your Height is “ + height);
}
}

class AccessHuman
{
public static void main(String []args)
{
Human h1=new Human(); // Object Creation
h1.setValues(15,4); // Access Methods
h1.getValues(); // By Object
}
}

What is the difference between an object and a class? [ICSE 2011]

Class Object

A class is a blueprint of a real world object. It contains instance variables and methods.

An object is an instance of a class.

A class exists in the memory of a computer.

An object does not exist in memory in a computer.

There will be only one copy of a class.

Multiple objects can be instantiated from the same class.

softetechnologies
    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post