Relation between class and object

Can you explain the relation between class and object? Explain with an example

A class defines the properties and behavior for the objects represented by the abstraction. Abstraction is a property of object oriented programming. It denotes the essential properties and behaviors of an object. It hides code and data. A class thus denotes a category of objects and act as a blueprint for creating such objects. An object exhibits the property and behaviors defined by its class. Generally, an object is an instance of a class.

For example:
// program for adding two numbers

class sum //declaration of a class

{

   int a=10; //declaration of variables

   int b=20;

   int c;

   public void add()// defining a function

   {

      c=a+b;

      System.out.println("The sum is="+c);

   }

   public static void main(String args[])// main function

   {

       sum s= new sum();// making a object of class sum

       s.add();

       //accessing the function with the help of object

   }

}
Difference between throw and throws clause
Throw and throws clause - A program can throw an exception, using throw statement. When an exception is thrown, normal execution is suspended...
Tomcat in java and its usage
Tomcat in java and its usage - Tomcat is an open source servlet container. It was developed by Apache Software Foundation. It is commonly known as Apache Tomcat. It is a web server for the processing of JSP and Java Servlets. When a programmer makes web applications by using servlets or JSP then a .war file is made by compressing the application folder...
Difference between Tomcat and Weblogic server
Tomcat and Weblogic server - Tomcat is a web server which can run servlets and JSP whereas Weblogic is an application server which can run EJBs also...
Post your comment