class in java

Java Class -: A class is a group of related object .We know that the  Java is an object oriented programming language .Like any other programming language java support many class in java. All file in a Java program defines a class. Any code in a Java program is inside a class. There is nothing like global variables or global functions as in C programming,  Python, Go, or other languages. Java is totally object oriented.

Rules of define a class.

A class is defined using the class keyword and each class has  a name. The name should be unique within the package  and has to be the same as the name of the file.

A class can implement an interface or extend another class.

A class can also be abstract, final, and public. These are defined with the appropriate keywords.

The class starts at the beginning of the file right after the package declaration and everything between the { and } characters belong to the class.

The methods, fields, inner or nested classes and so on are part of the class.

Generally, curly braces denote some block in Java. This was invented in the C language  and many other languages .

Class declaration is some block, methods are defined using some block, loops, and conditional commands use blocks.

Declare a class in java-: Like any other programming language it is necessary to declare a class name. The syntax of class declare is ..

class classname {
 
}

For example of class

public class Dog {
   String breed;
   int age;
   String colour;

   void barking() {
   }

   void hungry() {
   }

   void sleeping() {
   }
}

 

Types of class in java -: We know the class are the  group of related objects. according the use of class are divided

Java Inner class-: A class can also be declare another class it is called the inner class. For example

package com.jdojo.innerclasses;

public class Outer {
       public class Inner {
               // Members of the Inner class go here
       }
       // Other members of the Outer class go here
}

 

Abstract class in java-: A class which is declare the abstract class called the abstract class.

Wrapper class in java-: all the wrapper class as like int, long ,float, double byte, all are part of wrapper class.

According the modifier there are four type class

  • Public Class
  • Private Class
  • Protected Class
  • Default Class.

 

 

Leave a Comment