| A class is a group of objects that has common properties. It is a template or blueprint from which objects are created. |
A class in java can contain:
- data member
- method
- constructor
- block
- class and interface
Syntax to declare a class:
- class <class_name>{
- data member;
- method;
- }
Simple Example of Object and Class
In
this example, we have created a Student class that have two data
members id and name. We are creating the object of the Student class by
new keyword and printing the objects value.
- class Student1{
- int id;//data member (also instance variable)
- String name;//data member(also instance variable)
- public static void main(String args[]){
- Student1 s1=new Student1();//creating an object of Student
- System.out.println(s1.id);
- System.out.println(s1.name);
- }
- }
For more Visit: http://www.quontrasolutions.com/blog/category/java
No comments:
Post a Comment