instanceof java
Posts: 576
Nickname: instanceof
Registered: Jan, 2015
instanceof java is a java related one.
Static class in java
Posted: Jul 11, 2015 1:04 PM
This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Static class in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java
Advertisement
Yes we can create a class as static. But class should be inner class or nested class. We know how to create static methods , static variables and static blocks. As Java Supports defining a class within a class we can create a static inner class inside a class. This inner static class inside a class can access static members of outer class even its private.
Java Program to create static inner class: package instanceofjavaTutorial; public class Outer{ static class inner{ public void print(){ System.out.println("static inner class method called"); } } public static void main(String args[]){ Outer.inner in= new Outer.innner(); in.print(); } } Output: static inner class method called Static inner class accessing outer class static variable: package instanceofjavaTutorial; public class Outer{ static int a=10; static class inner{ public void print(){ System.out.println(a); } } public static void main(String args[]){ Outer.inner in= new Outer.innner(); in.print(); } } Output: In java there are two types of nested classes one is static and another one is non static nested classes. We saw static classes in java lets see what will be there in non static nested classes. Non-static nested class(inner class)
Member inner class Anonymous inner class Local inner class A class is defined within a class and outside of methods of that class known as member inner class. Anonymous inner class is a inner class which does not have a name and whose instance is created at the time creating class itself. A class which is defined inside a method of another class known as local inner class Click here for more information about inner classes
Read: Static class in java