Java - Calling Non Static Members Directly From Constructor Without Using the Object Name Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 4 Likes Like Report Java is an Object-Oriented Programming(OOP) language. We need to create objects in order to access methods and variables inside a class. However, this is not always true. While discussing static keywords in java, we learned that static members are class level and can be accessed directly without any instance. Here we will be discussing how we can access non-static data members without using the object name for which let us compare static data members and non-static data members which are as provided in the below table as follows: Static Data MembersNon-Static Data MembersThey are declared using the keyword 'static'.Every member in java defaults to a non-static without a 'static' keyword preceding it.All objects of a class share the same copy of static data members.Each object of the class gets its own copy of Non-Static data members.They can be accessed using the class name or object.They are generally accessed through an object of the class.Static methods can be called without the instance or object of that class. Non-static methods can access any static method and static variable, without creating an instance of the object. Example 1: Calling static data members without the instance or object of that class. Java // Java program Illustrating Calling Static Data Members // Without the Instance or object of that class // Main class public class GFG { // Static variable static int a = 5; // Method 1 // Static method static void f() { // Print statement whenever static method is called System.out.println("I am static method"); } // Method 2 // Main driver method public static void main(String[] args) { // Calling static data members without the // instance or object of that class. System.out.println(GFG.a); // Calling method 1 GFG.f(); } } Output5 I am static method Example 2: Calling non-static data members. Java // Java Program Illustrating Calling Non-static Data Members // Main class public class GFG { // Non-static variable int a = 5; // Method 1 // Non-static method void f() { // Print statement whenever non static method is // called System.out.println("I am Non-static method"); } // Method 2 // Main driver method public static void main(String[] args) { // Creating object of class inside main() GFG obj = new GFG(); System.out.println(obj.a); // Calling non static data members obj.f(); } } Output5 I am Non-static method Example 3: Calling non-static data members directly without using object names. Java // Java program Illustrating Calling Non-static Method // Without using Object Name // Main class class GFG { // Calling non-static method // through constructor GFG() { int a = 5; System.out.println(a); display(); } // Method 1 // Non static method void display() { // Print statement whenever non-static method is // called System.out.println( "Non static method is called using constructor."); } // Method 2 // Main driver method public static void main(String[] a) { new GFG(); } } Output5 Non static method is called using constructor. Create Quiz Comment D dattabikash505 Follow 4 Improve D dattabikash505 Follow 4 Improve Article Tags : Java Blogathon Blogathon-2021 Java-Constructors Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like