Java
Java
and Method
• Abstract class
Types of • 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.
• The properties of the static class are:
• The class has only static members.
• It cannot access the member (non-static) of the outer class.
• We cannot create an object of the static class.
• A static method belongs to the class rather than the object of a class.
• A static method can be invoked without the need for creating an instance of a
class.
• A static method can access static data member and can change the value of it.
• public class Outer {
• static class Nested_Demo {
• public void my_method() {
• System.out.println("This is my nested class");
• }
• }
• public static void main(String args[]) {
• Outer.Nested_Demo nested = new
Outer.Nested_Demo();
• nested.my_method();
• }
• }
Final Class
• The word final means that cannot be changed. The final class in Java can be
declared using the Final class. 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.
• final class ParentClass {
• void showData() {
• System.out.println("This is a method of final Parent class");
• }}
• class ChildClass extends ParentClass {
• void showData() {
• System.out.println("This is a method of Child class");
• }
• }
• class MainClass
• {
• public static void main(String arg[])
• {
• ParentClass obj = new ChildClass();
• obj.showData();
• }
• }
• An abstract class is a that is declared with
the keyword abstract. The class may or
may not contain abstract methods. We
cannot create an instance of an abstract class
but it can be a subclass. These classes are
incomplete, so to complete the abstract class
we should extend the abstract classes to a