create object of static class in java
Java
// Java program to demonstrate how to
// implement static and non-static
// classes in a Java program.
class OuterClass {
private static String msg = "GeeksForGeeks";
// Static nested class
public static class NestedStaticClass {
// Only static members of Outer class
// is directly accessible in nested
// static class
public void printMessage()
{
// Try making 'message' a non-static
// variable, there will be compiler error
System.out.println(
"Message from nested static class: "
+ msg);
}
}
// Non-static nested class -
// also called Inner class
public class InnerClass {
// Both static and non-static members
// of Outer class are accessible in
// this Inner class
public void display()
{
System.out.println(
"Message from non-static nested class: "
+ msg);
}
}
}
class Main {
// How to create instance of static
// and non static nested class?
public static void main(String args[])
{
// Create instance of nested Static class
OuterClass.NestedStaticClass printer
= new OuterClass.NestedStaticClass();
// Call non static method of nested
// static class
printer.printMessage();
// In order to create instance of
// Inner class we need an Outer class
// instance. Let us create Outer class
// instance for creating
// non-static nested class
OuterClass outer = new OuterClass();
OuterClass.InnerClass inner
= outer.new InnerClass();
// Calling non-static method of Inner class
inner.display();
// We can also combine above steps in one
// step to create instance of Inner class
OuterClass.InnerClass innerObject
= new OuterClass().new InnerClass();
// Similarly we can now call Inner class method
innerObject.display();
}
}
Also in Java:
- Title
- java string to char array
- Category
- Java
- Title
- java 8 seconds to days
- Category
- Java
- Title
- sort array java
- Category
- Java
- Title
- kotlin vs java
- Category
- Java
- Title
- add a value to a list java in java hashmap
- Category
- Java
- Title
- how to open a folder in java swing project
- Category
- Java
- Title
- java hello world
- Category
- Java
- Title
- java implement interface
- Category
- Java
- Title
- java string copy characters
- Category
- Java
- Title
- java convert char to int
- Category
- Java
- Title
- google translate
- Category
- Java
- Title
- binary to int java
- Category
- Java
- Title
- check if list contains new line in java
- Category
- Java
- Title
- casting java
- Category
- Java
- Title
- java create clas
- Category
- Java
- Title
- java last element in array
- Category
- Java
- Title
- android hide and show bottom navigation
- Category
- Java
- Title
- how do you concatenate an int with a string in java
- Category
- Java
- Title
- how to create a linked list in java
- Category
- Java
- Title
- java projects
- Category
- Java
- Title
- java sleep in code
- Category
- Java
- Title
- javadoc reference general toString
- Category
- Java
- Title
- sum of arraylist java 8
- Category
- Java
- Title
- how to make a text field required in android studio
- Category
- Java
- Title
- Manifest merger failed androidx
- Category
- Java
- Title
- how to find the divisors of a number in java
- Category
- Java
- Title
- java processbuilder example
- Category
- Java
- Title
- java enum
- Category
- Java
- Title
- two dimensional array in java example program
- Category
- Java
- Title
- time conversion solution
- Category
- Java
- Title
- import java.util.hashset
- Category
- Java
- Title
- How to loop through objects in java using streams
- Category
- Java
- Title
- how to get witdth of window android
- Category
- Java
- Title
- in java how to compare two strings
- Category
- Java
- Title
- Java arraylist if you don't want to use add()
- Category
- Java
- Title
- java - get open ports
- Category
- Java
- Title
- java string indexof
- Category
- Java
- Title
- working with buttons in applet java
- Category
- Java
- Title
- shorthand if java without else
- Category
- Java
- Title
- read from elasticsearch in spark
- Category
- Java
- Title
- java iterate over a string
- Category
- Java
- Title
- como detener un void java
- Category
- Java
- Title
- actionListener java
- Category
- Java
- Title
- dates in java 8
- Category
- Java
- Title
- cosinus-1 java
- Category
- Java
- Title
- Create ArrayList from array java
- Category
- Java
- Title
- how to write a merge sort array method ni java
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- binary numbers java
- Category
- Java
- Title
- how to compare two maps in java
- Category
- Java
- Title
- error message pushes button down
- Category
- Java
- Title
- string to arraylist convert java
- Category
- Java
- Title
- nextchar in java
- Category
- Java
- Title
- lightweight java game library
- Category
- Java
- Title
- java read file bufferedreader
- Category
- Java
- Title
- print arraylist java
- Category
- Java
- Title
- how to import a scanner in java
- Category
- Java
- Title
- toString convert to long
- Category
- Java
- Title
- java do while
- Category
- Java
- Title
- double to string java
- Category
- Java
- Title
- java int to binary
- Category
- Java
- Title
- how to create a button in java
- Category
- Java
- Title
- arraylist add method
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- java check if int
- Category
- Java
- Title
- what is a float java
- Category
- Java
- Title
- fastapi list query parameter
- Category
- Java
- Title
- how to get the max value of an array java
- Category
- Java
- Title
- print map java
- Category
- Java
- Title
- expression régulière téléphone java
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- how to create a method java
- Category
- Java
- Title
- java permutation
- Category
- Java
- Title
- arraylist in java
- Category
- Java
- Title
- hashmap in java
- Category
- Java
- Title
- convert int to string java
- Category
- Java
- Title
- place.getlatlng() returning null
- Category
- Java
- Title
- try block in java
- Category
- Java
- Title
- java how to show an array
- Category
- Java
- Title
- print in one line in java
- Category
- Java
- Title
- how to use spring in java
- Category
- Java
- Title
- java uuid
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- how to check if in array java
- Category
- Java
- Title
- how to send http post create request using curl command
- Category
- Java
- Title
- append to arraylist by index java
- Category
- Java
- Title
- get sha key android
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- run spring boot application command line
- Category
- Java
- Title
- java get current milliseconds
- Category
- Java
- Title
- convert hashset to array
- Category
- Java
- Title
- java check if directory exists
- Category
- Java
- Title
- how to limit double decimal places java
- Category
- Java
- Title
- how to convert a jsonobject to a dbobject
- Category
- Java
- Title
- how to do a linear searc in java
- Category
- Java
- Title
- what is a variable in java
- Category
- Java
- Title
- import java.util.*;
- Category
- Java
- Title
- uppercase java
- Category
- Java
- Title
- public static void main(string args)
- Category
- Java
- Title
- java classes and methods simple logic with comments
- Category
- Java