int age;
int name;
public abstract void animalNoise();
public abstract void printInfo();
}
public class Cat extends Animal{
public void printInfo(String n){
@Override
this.name=n;
System.out.println(this.name);
}
}
public class Main
{
public static void main(String[] args) {
Cat c=new Cat();
c.printInfo("Voyla");
}
}
#Whys is this showing error ?
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
<@&987246399047479336> please have a look, thanks.
Could anyone please help ?
why is @Override there?
hello
what is the error ?
Whilst yes... That's an error. but in the tradition of teaching them to fish... What is the compiler error you're getting?
override should be on a method
not on a field
or a call
This is the error I use override too
yeah,I am
The original error about the incompatibility of the type is correct... Adding @Override is invalid and makes no sense there - leaving you with a different error.
no worries, thats why ur here and we will help u 🙂
Oh
How do i fix this
alright, in that case, i'd suggest you to learn from a course
Thank you
int name - this is the declaration of name in the parent class. When you say this.name you're referring to this field (of type int) but trying to assign it a reference to a String (n).
Why is this error coming ?
ur animal class declared
public abstract void animalNoise();
public abstract void printInfo();
that means that any implementation of this class, for example Cat, must provide these two methods - exactly as stated
but two issues with that:
- ur cat has no
void animalNoise()method yet - u also dont have a
void printInfo()method yet, u havevoid printInfo(String), but thats not the same
the @Override annotation is helpful and we will get to that in a second - but note that it doesnt influence the actual override-mechanism in java.
the root issue is that ur simply not providing the methods stated by Animal
int age;
int name;
public abstract void printInfo(String n);
}
public class Cat extends Animal{
public void printInfo(String n){
@Override
this.name=n;
System.out.println(this.name);
}
}
public class Main
{
public static void main(String[] args) {
Cat c=new Cat();
c.printInfo("Voyla");
}
}
Detected code, here are some useful tools:
Formatted code
public abstract class Animal {
int age;
int name;
public abstract void printInfo(String n);
}
public class Cat extends Animal {
public void printInfo(String n) {
@Override
this .name = n;
System.out.println(this .name);
}
}
public class Main {
public static void main(String[] args) {
Cat c = new Cat();
c.printInfo("Voyla");
}
}
Now ive did it
yeah, but is that meaningful?
why do u want printInfo to take an argument?
shouldnt it just print the info of the animal
without the user giving an extra string
and what about ur animalNoise method, why did u remove it entirely?
@buoyant breach
MOOC is a completely free introductory Java course created by the University of Helsinki, it is a great way to learn Java from the ground up.
It consists of two parts, one at beginner, and another at intermediate level. The end of the course is marked by creating your own Asteroids game clone!
Even though the instructions show how to configure and use NetBeans for the course, you can use IntelliJ. To use IntelliJ, simply install the TMC plugin by opening IntelliJ -> File -> Settings -> Plugins and searching for TMC. You will then be able to use IntelliJ to complete MOOC.
Visit MOOC here: https://java-programming.mooc.fi/
(the course is available in both English and Finnish)
firasrg5942 • used /tag id: mooc reply-to: @manoban4720
·
About the course - Java Programming