Rohit Gupta
What are the types of Classes in Java?
By Rohit Gupta in Java on Sep 10 2019
  • Laxmidhar Sahoo
    Jan, 2020 8

    POJO Class

    POJO stands for “Plain Old Java Object”. A class which contains only private variables and setter and getter methods to use those variables is called POJO class

    Static Class

    In Java, static is a keyword used to describe how objects are managed within the memory. A static object belongs specifically to the class, instead of instances of that class. The sole purpose of the class is to provide blueprints of its inherited classes. A static class can contain static members only. You cannot create an object for a static class.

    Inner class
    Inner class means the class which is a member of another class. There are four types of inner classes in java.
    1) Nested Inner class
    2) Method Local inner classes
    3) Anonymous inner classes
    4) Static nested classes

    Concrete Class

    Any normal class which does not have any abstract method or a class having an implementation for all of its methods is basically a concrete class. They cannot have any unimplemented methods. A concrete class can extend its parent class, an abstract class or implement an interface if it implements all their methods. It is a complete class that can be instantiated.

    Abstract Class

    An abstract class is declared with an abstract keyword and have zero or more abstract methods. These classes are incomplete classes, therefore, to use an abstract class we strictly need to extend the abstract classes to a concrete class. It can have constructors and static methods as well. It can have final methods which will force the subclass to keep the body of the method unhung.

    Final Class

    Once a variable, method or a class is declared as final, it’s value remains the same throughout. The final keyword in a method declaration indicates that the method cannot be overridden by any subclasses i.e., a class that has been declared final cannot be subclassed. This helps a lot while creating an immutable class like the String class. A class cannot make a class immutable without making it final

    • 0
  • Vijay Kumari
    Sep, 2019 16

    In Java, There are 4 major types of classes.

    1. Abstract Java Classes
      Abstract Java class can have abstract methods and non-abstract methods.
      If a class have an abstract method, this class must be abstract Java class.
      If we want to use an abstract class, it needs to be extended and its methods implemented.

    2. Nested Java Classes
      Java programming language allows you to define a class within another class. We use the nested class to logically group of the class and interface in one place It can be more readable maintainable and can access all the members of the outer class(public, private, protected).

    3. Final Java Classes
      When we use the final with any class, it is called a final Java class. A final class can’t be inherited. If any class is declared final then all its methods implicitly get declared as final.

    4. Singletan Java class

    In object-oriented programming, a singleton class is a class that can have only one object at a time. Singletons often control access to resources, such as database connections or sockets. The intention is to create a single instance of an object of classes which are expensive to create during runtime and try to reuse the same object.

    For a Detailed tutorial on Java Classes, visit
    https://www.c-sharpcorner.com/article/a-complete-java-classes-tutorial/

    • 0

Most Popular Job Functions


MOST LIKED QUESTIONS