Results 1 to 4 of 4
Thread: Interface methods
- 12-26-2011, 08:23 AM #1
Interface methods
I'm a beginner too. I've been having the same problems. Could anyone just tell me what modifications must be made for the below program to work(that is no more"weaker access privileges" stuff)
fandemo.java
The error is like the method in the class cannot implement the one in the interface etc.Java Code:interface fani { void switch_on(); void switch_off(); void faster(); void slower(); void state_info(); } class fan implements fani { int power=0; /** POWER; 1=ON; 0=OFF*/ int speed=1; /** SPEED=1,2,3,4. */ void switch_on() { power=1; //switch on the fan } void switch_off() { power=0; //switch off the fan } void faster() { if(speed==4)return; //maximum speed else speed++; //increase speed one step } void slower() { if(speed==1)return; //minimum speed else speed--; } void state_info() { System.out.print("\n power="+power+" and speed="+speed); //print the state of fan } } class fandemo { public static void main(String args[]) { int a; fan fan1=new fan(); fan fan2=new fan(); //two fans System.out.println("Hello there!! \n"); fan1.switch_on(); fan1.faster(); fan1.faster(); fan1.state_info(); System.out.printf("\n"); fan2.state_info(); } }
Pls help.
- 12-26-2011, 11:24 AM #2
Re: Interface problem
wht if suppose we make the methods of the class fan as public with proper return type?
Rajiv Joshi.gif)
- 12-26-2011, 12:13 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Interface methods
I moved these posts from an old thread to this new thread. Next time don't resurrect an old zombie thread but start your own new thread.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-26-2011, 12:48 PM #4
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
Incorporating If-Else into Methods + Private Helper Methods?
By 5minutes in forum New To JavaReplies: 1Last Post: 10-05-2011, 12:15 AM -
how to call or use methods inside interface?
By akhmad in forum New To JavaReplies: 2Last Post: 11-10-2010, 09:55 AM -
Methods that are NOT defined in interface
By johto760 in forum New To JavaReplies: 7Last Post: 10-29-2010, 06:31 PM -
Why methods in an interface cannot be static?
By cbalu in forum Advanced JavaReplies: 2Last Post: 12-12-2007, 07:57 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks