Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Interface

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Interface

    Can a class be defined inside an Interface .

     interface Inter{
    	class x{
    		public static void main(String[] args){
    			System.out.println("Hello World!");
    		}
    	}
    }


  2. #2
    Junior Member Tjones787's Avatar
    Join Date
    Jan 2014
    Location
    Lagos, Nigeira
    Posts
    16
    My Mood
    Asleep
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Interface

    An interface can only contain constants and abstract methods.
    Tjones787

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Interface

    Quote Originally Posted by gautammuktsar@gmail.com View Post
    Can a class be defined inside an Interface .

     interface Inter{
    	class x{
    		public static void main(String[] args){
    			System.out.println("Hello World!");
    		}
    	}
    }
    Yes, it's perfectly legal. The class is not an "inner" class, it is a "nested" (static) class.
    Beware that this is very uncommon and quite never used (unless in extreme/particular designs). So please, don't do this.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

Similar Threads

  1. interface
    By tungan91 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 13th, 2012, 09:50 PM
  2. Interface?
    By jean28 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 14th, 2012, 01:02 AM
  3. Interface
    By Samaras in forum Java Theory & Questions
    Replies: 2
    Last Post: August 4th, 2012, 06:27 PM
  4. Interface
    By kaasi in forum Member Introductions
    Replies: 4
    Last Post: April 21st, 2011, 11:45 AM
  5. interface
    By nasi in forum Object Oriented Programming
    Replies: 5
    Last Post: September 2nd, 2010, 11:36 PM