A
A
Andrey Chistov2020-03-02 21:22:16
Java
Andrey Chistov, 2020-03-02 21:22:16

Why doesn't it compile Java code?

gives an error when compiling

SeriesDemo.java:1: error: cannot find symbol
class ByTwos implements Series {
                        ^
  symbol: class Series

help me figure out what is the problem?

class ByTwos implements Series   {
  int start;
  int val;
  ByTwos() {
  start = 0;
  val = 0;
  }
  public int getNext() {
  val +=2;
  return val;
  }
  public void reset() {
  start = 0;
  val = 0;
}
  public void setStart(int x) {
  start = x;
  val = x;
  }
}
class SeriesDemo {
  public static void main(String args[]) {
    ByTwos ob =  new ByTwos();

  for (int i =0; i <5; i++)
  System.out.println("Next value is" + ob.getNext());

  System.out.println("\nResetting");
  ob.reset();
  for(int i=0; i<5; i++)
  System.out.println("Next value is" + ob.getNext());

  System.out.println("\nStarting at 100");
  ob.setStart(100);
  for(int i=0;i<5;i++)
  System.out.println("Next value is" + ob.getNext());
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stavr Strelov, 2020-03-05
@IAmNoob

Java does not know the Series interface!
Perhaps it does not exist, perhaps you forgot to create it, perhaps it is not an interface, but a parent class, and then instead of implements you need to write extends, perhaps you forgot to import it)
Most likely you just need to import it using the word import at the beginning class file!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question