Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:21:16+00:00 2026-05-27T12:21:16+00:00

I have the following interface and abstract class that implements it: interface Walk {

  • 0

I have the following interface and abstract class that implements it:

interface Walk {
    String walk();
}

public abstract class Animal implements Walk {
    abstract String MakeNoise();
}

And the following concrete implementations:

class Cat extends Animal {
    String MakeNoise() {
        return "Meow";
    }

    @Override
    String walk() {
        return "cat is walking";
    }
}

class Dog extends Animal {
    @Override
    String walk() {
        return "Dog is walking";
    }

    @Override
    String MakeNoise() {
        return "bark";
    }
}

class Human {
    public void Speak() {
        System.out.println("...Speaking...");
    }
}

Putting it all together:

class MainClass {
    public static void main(String[] args) {
        Random randomGen = new Random();

        Animal[] zoo = new Animal[4];
        zoo[0] = new Cat();
        zoo[1] = new Dog();
        zoo[2] = new Cat();
        zoo[3] = new Cat();
        // System.out.println(zoo[ randomGen.nextInt(2)].MakeNoise());
        for (Animal animal : zoo) {
            if (animal instanceof Dog) {
                Dog jeffrey = (Dog) animal;
                System.out.println(jeffrey.MakeNoise());
            }

        }
    }
}

I get this error

“walk() in Cat cannot implement walk() in Walk ” .

Any ideas? thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:21:17+00:00Added an answer on May 27, 2026 at 12:21 pm

    Methods in interfaces are implicitly public. However, methods in classes are package-visible by default. You cannot reduce the visibility of an overriden method, i.e. you can’t do stuff like this:

    class A {
        public foo() {}
    }
    
    class B extends A {
        private foo() {}  // No!
    }
    
    class C extends A {
        foo() {}          // No! foo is package-visible, which is lower than public
    }
    

    In your case, the solution is to declare walk() as public in Dog and Cat.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like following: public interface A { .... } public abstract class
Please consider the following three .NET types: I have an interface, an abstract class,
I have an abstract class that looks as follows. public abstract class Entity<PK extends
I have the following idea: Business object implemented as interface or abstract class with
Assume I have the following abstract class and use it as an interface in
i have the following classes and mappings abstract class BaseClass { public virtual int
Imagine we have following classes: public interface MyInterface<T> { List<T> getList(T t); } abstract
I have the following class: <?php /* * Abstract class that, when subclassed, allows
Consider the following example. I have an interface MyInterface, and then two abstract classes
I have the following interface defined to expose a .NET class to COM: [InterfaceType(ComInterfaceType.InterfaceIsDual)]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.