JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Program: How to initialise or call a static member class?


Description:
A static member class must me declared as a static member of top level class.
Static member class can not have its name as top level class.

Code:
package com.java2novice.nested.classes;

public class MyBasicStaticMemberClass {

	public static class MyStaticMemberExampleClass {

		public void printStatus() {
			System.out.println("Hey I am inside static member class");
		}
	}

	public static void main(String a[]) {
		StaticMemberTestClass smt = new StaticMemberTestClass();
		smt.testMemberClass();
	}
}

class StaticMemberTestClass {

	public void testMemberClass() {
		MyBasicStaticMemberClass.MyStaticMemberExampleClass msme 
					= new MyBasicStaticMemberClass.MyStaticMemberExampleClass();
		msme.printStatus();
	}
}

Output:
Hey I am inside static member class
 Next Program >>
blog comments powered by Disqus

Java Nested Classes Sample Code Examples

  1. How to initialise or call a static member class?
  2. How to implement a static member interface?
  3. How to access top level class variables from static member classes?
  4. Give an example of basic non-static member class.
  5. How to initialise non-static member (local class) class?
Knowledge Centre
Can we override static method?
We cannot override static methods. Static methods are belogs to class, not belongs to object. Inheritance will not be applicable for class members
Famous Quotations
The greatest obstacle to discovery is not ignorance; it is the illusion of knowledge.
-- Daniel J. Boorstin

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.