• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

attempting to assign weaker access privileges;

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.

from the java tutorial I have this.

http://java.sun.com/docs/books/tutorial/java/IandI/createinterface.html


C:\>type Direction.java
public enum Direction
{
LEFT, RIGHT
}


which compiles fine,

in the file OperateBMW760i.java I have tried to compile the file as published on the web

public class OperateBMW760i implements OperateCar {

// the OperateCar method signatures, with implementation --
// for example:
int signalTurn(Direction direction, boolean signalOn) {
//code to turn BMW's LEFT turn indicator lights on
//code to turn BMW's LEFT turn indicator lights off
//code to turn BMW's RIGHT turn indicator lights on
//code to turn BMW's RIGHT turn indicator lights off
}

// other members, as needed -- for example, helper classes
// not visible to clients of the interface

}


and with my own coding, like this







I end up with several error messages.

even after appending code and removing some methodes.

C:\DOKUME~1\ADMINI~1.7-0>javac -Xlint OperateCar.java

C:\DOKUME~1\ADMINI~1.7-0>javac -Xlint OperateBMW760i.java

OperateBMW760i.java:1:

OperateBMW760i is not abstract
and does not override abstract method
changeLanes(Direction,double,double) in OperateCar
public class OperateBMW760i implements OperateCar
^
OperateBMW760i.java:13: getRadarRear(double,double) in OperateBMW760i cannot imp
lement getRadarRear(double,double) in OperateCar; attempting to assign weaker ac
cess privileges; was public
int getRadarRear(double distanceToCar, double speedOfCar)
^
OperateBMW760i.java:8: getRadarFront(double,double) in OperateBMW760i cannot imp
lement getRadarFront(double,double) in OperateCar; attempting to assign weaker a
ccess privileges; was public
int getRadarFront(double distanceToCar, double speedOfCar)
^
OperateBMW760i.java:3: signalTurn(Direction,boolean) in OperateBMW760i cannot im
plement signalTurn(Direction,boolean) in OperateCar; attempting to assign weaker
access privileges; was public
int signalTurn(Direction direction, boolean signalOn)
^
4 errors


Please help, it must be something I have overlooked.

public interface OperateCar compiles fine.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All methods in interfaces are implicitly public - and therefore need to be explicitly declared public in implementing classes.
 
Morten Gulbrandsen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok from the Java Tutorials
Lesson Interfaces and Inheritance I have this code,

public class OperateBMW760i implements OperateCar {

Direction direction;

public OperateBMW760i(Direction direction)
{
this.direction = direction;
}

// the OperateCar method signatures, with implementation --
// for example:
public int signalTurn(Direction direction, boolean signalOn) {
//code to turn BMW's LEFT turn indicator lights on


//code to turn BMW's LEFT turn indicator lights off
//code to turn BMW's RIGHT turn indicator lights on
//code to turn BMW's RIGHT turn indicator lights off

return 0;
}

Please how do I make a useful signalTurn function, It works with this method,

public void tellItLikeItIs()
{
switch (direction)
{
case LEFT: System.out.println("Left is bad.");
break;


public static void main(String[] args)
{
OperateBMW760i mortensBMW = new OperateBMW760i(Direction.LEFT);

mortensBMW.tellItLikeItIs();

OperateBMW760i mortens2BMW = new OperateBMW760i(Direction.RIGHT);

mortens2BMW.tellItLikeItIs();


}

and it runs and compiles fine

>javac -Xlint *.java

itance>java OperateBMW760i
Left is bad.
Right are better.


It would be fine if I could simulate something like 1 or 2 BMW cars driving randomely.

first turning on Light Indicator and then if getRadar tells ok
the lanes can be changed.

I have three files
public interface OperateCar {
public enum Direction {
public class OperateBMW760i implements OperateCar {
reply
    Bookmark Topic Watch Topic
  • New Topic