Abstract vs Public Access Modifier in Java Last Updated : 03 Mar, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Access Modifier in Java is the reserved keyword used to define the scope of a class, variable, and methods. It also tells us about that whether child class creation is possible or not or whether object creation is possible or not. Abstract Access Modifier is a modifier applicable only for classes and methods but not for variables. If we declare any method as abstract then that method must have its implementation in the child class of the respective class because abstract methods never talk about implementation. If any modifier talks about implementation then it forms an illegal combination with an abstract modifier. In a similar way if for any java class if we are not allowed to create an object (because of partial implementation) then such type of class we have to declare with abstract modifier. Example: Java // Java program to illustrate Abstract Access Modifier // Importing the required packages import java.io.*; import java.util.*; // Class 1 // Helper abstract class abstract class Vehicle { // Declaring an abstract method getNumberOfWheel abstract public int getNumberOfWheel(); } // Class 2 // Helper class extending above abstract class class Bus extends Vehicle { // Giving the implementation // to the parent abstract method public int getNumberOfWheel() { return 7; } } // Class 3 // Helper class extending above abstract class class Auto extends Vehicle { // Giving the implementation // to the parent abstract method public int getNumberOfWheel() { return 3; } } // Class 4 // Main class public class GFG { // Main driver method public static void main(String[] args) { // Creating Bus object Bus b = new Bus(); // Creating Auto object Auto a = new Auto(); // Now getting and displaying // the number of wheels // for Bus by calling the // getNumberOfWheel method System.out.println("Number of wheels in bus is" + " " + b.getNumberOfWheel()); // Now getting and displaying // the number of wheels // for Auto by calling the // getNumberOfWheel method System.out.println("Number of wheels in Auto is" + " " + a.getNumberOfWheel()); } } OutputNumber of wheels in bus is 7 Number of wheels in Auto is 3 Now dwelling onto the next modifier is the public Access Modifier. So If a class is declared as public then we can access that class from anywhere. We will be creating a package pack1 inside that package we declare a class A which is public and inside that class, we declare a method m1 which is also public. Now we create another package pack2 and inside that pack2 we import pack1 and declare a class B and in class B’s main method we create an object of type class A and trying to access the data of method m1.  Example 1: Java // Java Program to illustrate public modifier // Creating a package pack1 package pack1; // Declaring a class A public class A { // Declaring a public method m1 public void m1() { // Print statement System.out.println("GFG"); } } Output: Example 2: Java // Java Program to Illustrate Public Modifier // Creating package pack2 package pack2; // Importing package pack1; import java.io.*; // Importing the required modules import java.util.*; import pack1.*; // Main class // Declaring a class B class B { // Main driver method public static void main(String[] args) { // Creating object of type class A A b = new A(); // Now calling the method m1() A.m1(); } } Output:  Finally after having an adequate understanding of both of them let us conclude out the differences between them to click better understanding as depicted in the below table as follows:         Abstract Access Modifier           Public Access ModifierThis modifier is not applicable for variables. This modifier is applicable for variables.This modifier is not applicable for enum. This modifier is applicable for both outer and inner enum. This modifier is not applicable for constructors. This modifier is applicable for constructors. This modifier is more restricted than the public access modifier.This modifier is less restricted than the abstract access modifier. Comment More infoAdvertise with us Next Article Abstract vs Public Access Modifier in Java M mroshanmishra0072 Follow Improve Article Tags : Java Difference Between TrueGeek TrueGeek-2021 Java-Modifier +1 More Practice Tags : Java Similar Reads Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac 15+ min read Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an 13 min read Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt 10 min read Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Java Interface An Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to 12 min read Introduction to Java Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android 4 min read Like