Blog Image

CLASS IN JAVA

 


 


 


Definition


      “A class in java is set of objects which shares common characteristics/behaviour and common properties/attributes”


A class in java can contain


1.  Fields


2.  Methods


3.  Constructors


4.  Blocks


5.  Nested class and interface


The following components make up a class declaration


-       Modifiers


-       Class name


-       Keywords


-       The class body within curly brackets { }


Syntax of class


modifier      keyword     class name


Public class Demo {


       //body


}


Example


Public class Demo {


Public Static Void main( String [] args){


     System.out.println(“Hello World”);


   }


}


 


Output - Hello World


“A class should always start with an uppercase first letter, and that the name of the java file should match the class name”


Main class types


1. Concrete class


2. Abstract class


3. Final class


4. Nested class



 


Explain java class in easy word


-       Class is a blue print from which objects are created.


-       Class is a group of similar objects.


-       Class is a logical entity.


-       Class is declared once.


-       Class doesn’t allocated memory when it is created.


-       Class is declared using class keyword class Demo{ }


-       There is only one way to define a class, i.e. by using class keyword.


-       It does not occupy any memory space.


-       Class can exist without any object.


-       Class does not have any values associated with the fields.


 


Questions


1.  Define class with example?


2.  What is class syntax?


3.  What is main type of class?


4.  Explain class in java?


 


 

Author Photo

Dhanashri

Batch Number: Batch - 6