aspose file tools*
The moose likes Beginning Java and the fly likes errors while using interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "errors while using interface" Watch "errors while using interface" New topic
Author

errors while using interface

Dushyant Shukla
Greenhorn

Joined: Jan 13, 2013
Posts: 13
the code doesn't compiles as expected.Keeps giving the errors like
display() in volksWagon cannot implement display() in fourWheeler
attempting to assign weaker access privileges;was public.............................four other similar errors!



please help rectifying the code.....
Phil English
Ranch Hand

Joined: Jun 18, 2012
Posts: 62

If you don't explicitly tell the compiler what privileges are required to access a method the compiler will assign default (more properly known as package-private). If your interface mandates that the method is public then you are restricting access because default allows more limited access than public see here for more info on access modifiers

Try to set you method void display() to public void display() and see if that helps.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4246
    
    7

Hi Dushyant. Welcome to the Ranch!

In addition to what Phil said, interface methods are implicitly public (because interfaces are intended to define a public interface). So all the methods you've defined in fourWheeler are public. And therefore they need to be public in the class that implements them.

By the way, I'd recommend getting used to following Java conventions if you're going to program in Java. And one of those conventions is that interfaces and classes should start with a capital. It's a good idea to get into good habits early on.
Dushyant Shukla
Greenhorn

Joined: Jan 13, 2013
Posts: 13
thanks Phil sir and Matthew sir for your support and Matthew sir I will keep your suggestion in my mind....
The code is working fine after the changes besides the line 72 (pa=a.nextBoolean()).whenever i enter a yes/no or 1/0 it says Exception in thread "main" java.util.InputMismatchException....
what can be the possible errors...
thanks once again!
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4246
    
    7

You're welcome.

Dushyant Shukla wrote:The code is working fine after the changes besides the line 72 (pa=a.nextBoolean()).whenever i enter a yes/no or 1/0 it says Exception in thread "main" java.util.InputMismatchException....
what can be the possible errors...


Have you tried entering true/false?

When you're using a , if you want to be able to cope with unexpected input you sometimes need to use the "has..." methods. They tell you if the following input can be parsed as a particular type. So if you're about to use nextBoolean(), you can check hasNextBoolean() first. If that returns false, it means you're going to get an exception when you call nextBoolean().

And if you look at the Javadocs for java.util.Scanner#hasNextBoolean(), you'll see it says:

Returns true if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false".


If you want to be able to enter yes/no, you need to read the input as a String and compare it against String values.
Dushyant Shukla
Greenhorn

Joined: Jan 13, 2013
Posts: 13
Thanks a lot Matthew sir. The code is working fine now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: errors while using interface
 
Similar Threads
Please help - cloaning members within a superclass and class.
Error when using package
Car Inventory Problems
Writing to a file
Car class advice