JBAD_3

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Types of Classes in Java

• In Java, the class is a blueprint from which we can create an individual object.
• Java provides a Keyword named class by which we can declare a class.
• Inside the class, we define class members and functions.
• It is not possible to create Java programs without class.
• We can also refer a class as a user-defined data type because an object-oriented paradigm
allows us to model real-world objects.
• In this section, we will focus on the types of classes in Java.

1.Concrete Class
• A normal class with an implementation for all of its methods and no abstract methods is
called a concrete class.
• They are not permitted to have any processes that are not in use at the time.
• If it implements all of its methods, a concrete class can extend its parent, an abstract class, or
an interface.
• It’s a fully working, instantiable class.
2. Abstract Class
• A class that has zero or more abstract methods and is specified with the abstract keyword is
called an abstract class.
• We must rigorously extend the abstract classes to a concrete class in order to use them
because they are incomplete classes.
• Constructors and static methods can also be included.
• It can have final methods, which force the subclass to keep the body of the method
unhung.

3. Static Class
• In Java, static is a keyword that manage objects in the memory.
• The static object belongs to the class instead of the instance of the class.
• We can make a class static if and only if it is a nested class.
• We can also say that static classes are known as nested classes.
• It means that a class that is declared as static within another class is known as a static class.
• Nested static class does not require reference to the outer class.
• The purpose of a static class is to provide the outline of its inherited class.
4. Final Class

• The word final means that cannot be changed. The final class in Java can be declared using the final keyword.
• Once we declare a class as final, the values remain the same throughout the program.
• The purpose of the final class is to make the class immutable like the String class.
• It is only a way to make the class immutable.
• Remember that the final class cannot be extended. It also prevents the class from being sub-classed.

5. Inner class
• Java allows us to define a class within a class and such classes are known as nested classes.
• It is used to group the classes logically and to achieve encapsulation.
• The outer class members (including private) can be accessed by the inner class.
• The general syntax for declaring the nested class is as follows:

class OuterClass
{
//code
class NestedClass
{
//code
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy