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 4 of 4

Thread: default method in Interface

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

    Default default method in Interface

     interface I1{
         void show();
         void display();
         default void put(){
               System.out.println("I am from interface I1");
         }
     
     
     }
     
     class Access implements I1{
          public void show(){
              System.out.println(" Show method" );
          }
    	  public void display(){
    	      System.out.println("Display method ");
    	  }
    }	
     
    class InterfaceDemo {
        public static void main(String args[]){
    		I1 obj = new Access();
     
    		obj.show();
    		obj.display();
    		obj.put();
     
    	}
    }

    this code is not working..please fix it


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: default method in Interface

    You cannot provide implementation for a method in an interface. An interface can only contain method declarations.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: default method in Interface

    this code is not working
    That's nice...care to tell us what's wrong? Does it compile? Are there exceptions? Have you read the following (esp. the draft notice that is currently present at the top of the page)?
    Default Methods (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)

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

    Default Re: default method in Interface

    got it .. these are features and conventions of the upcoming Java SE 8 ..

Similar Threads

  1. Replies: 4
    Last Post: June 6th, 2013, 10:30 AM
  2. [SOLVED] How can I access my secondary interface method in my for loop?
    By bdennin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 12th, 2013, 06:29 PM
  3. method not passing across actionlistener interface
    By flamewolf393 in forum AWT / Java Swing
    Replies: 9
    Last Post: November 16th, 2011, 07:16 AM
  4. "Static method cannot hide instance method from implemented Interface"
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 21st, 2011, 03:03 AM
  5. Replies: 1
    Last Post: June 13th, 2011, 07:02 PM