What is a class In JAVA & its type ?

Classes in JAVA

The class is refund as a group of objects that can be one or more than one object, which represents the class.

In JAVA  a class  is declare by using a class keyword. the class  body is enclosed by between curly brace({}). the data or variable define within a class are instance variable, the code is contain within methods. 

Syntax :-

class class_name
{
     data member;
     method creation
}

The data members define within a class are called as instance variable.

There are no restriction on the sequence of data members.

A class can contain any of the following variable.

1 )- local Variable,
2 )- instance Variable.
3 )- class Variable.

Types of  Classes :-
What is a class In JAVA & its type ?
Classes in JAVA

There are 4 types of classes :-

1 )- public class.
2 )- private class.
3 )- abstract class.
4 )- final class.

1)- Public class :-



Public is a java keyword, Public is the access modifier, which declares a member’s access as public. Public members are accessible to all other classes. This means that any other class can access a public field or method.

Syntax :- 
                 public class class_name
                  {
                          
                       
                       
                  }

2 )- Private class :-

Private is a Java keyword, It is the most restrictive of  all  accessibility modifier, the members of this class are accessible only within the same class.
The members of private class are not accessible from any other class within a class package.

Syntax :-
                private class class_name
                 {
                     
                 }

3 )- Abstract class :- 

If we want to make classes represent base class and don't want anyone to create an object of this class then this can be achieved by using abstract class. This class can contain abstract as well as non-abstract member, but it is compulsory to have one abstract method in an abstract class.

Syntax :-
                  abstract class class_name
                   {
                         
                   }
The  implementation of the abstract method written in the abstract class is done in derived class.

4 )- final class :-

Java class with final modifier is called the final class in JAVA. It specifies a class that class doesn't have a subclass. final & abstract class can't be an abstract in Java. several classes in Java are final.

String class, integer class, & other wrapper classes.

Syntax :-
                 final class class_name
                 {
                   
                  }



Note :- in next blog i'm going to explain Access modifierobject in java & methods in java.


Post a Comment

0 Comments