Class or Interface excepted [closed] - java

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Here is the code:
public class Tuna {
public void eat() {
System.out.println("I am a tuna fish"); // Here it says class or interface excepted
}
}
I have a Tuna class above that has a eat method. In that eat method, it says class or interface expected at the print line. Even though it is running smoothly, when I hover over the print line in the eat method it says class or interface expected. I already checked other questions related to it but I couldn't solve it. Any help is appreciated.

Related

in Java I get an error, that says close parenthesis is expected [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
my Main class look like the following:
public class Main {
public static void main(String[] args)
{
Account account=new Account();
account.deposit(amount:10);
System.out.println(account.getBalance());
}
}
and Account class as below:
public class Account {
private float balance;
public void deposit(float amount){
if(amount>0)
balance+=amount;
}
}
I get an java ) expected error, which refers to the line "account.deposit(amount:10);" in Main class and hints, that amounts can not be resolved, but i dont understand why, could you give me some hint.
Change
account.deposit(amount:10);
to
account.deposit(10);
or
account.deposit(10.0f);
You can't label parameters that way at the caller's site. Also, don't forget to implement getBalance(). And use brackets ({}) even when they're optional.

JavaFX function takes any javaFX component? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
i wanna make a function that takes any javaFX element and sets an onMouseEntered event.
I tried to use generic type and extended it with only javaFX textfield but when i try to access the setOnMouseEntered method it says "Cannot resolve method 'setOnMouseEntered' in 'T'". How can i do that ?
public class sceneHandler<T extends javafx.scene.control.TextField> {
public <T> void onMouseUI(T obj){
obj.setOnMouseEntered(e->{
// Do something
});
}
}
Use the Node class, which is the base class for all JavaFX components:
public void onMouseUI(Node node){
node.setOnMouseEntered(e -> {
// Do something
});
}

How do I cast Stream.empty() in Java 8? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
All the examples I've found use other type information to infer the type of Stream.empty(). It seems like there should be syntax to allow me to cast it directly. This example works:
import java.util.*;
import java.util.stream.*;
class OptionalBasics {
static void test(Optional<String> optString) {
if(optString.isPresent())
System.out.println(optString.get());
else
System.out.println("Nothing inside!");
}
public static void main(String[] args) {
Stream<String> s = Stream.empty();
test(s.findFirst());
test(Stream.of("Epithets").findFirst());
}
}
/* Output:
Nothing inside!
Epithets
*/
But notice that I have to create s separately in order to provide type information for Stream.empty(). I'd like to just create it in the call to
test(), something like this (which doesn't work):
test(Stream<String>.empty().findFirst());
Is there a syntax for setting the type on the call to Stream.empty()?
You just have the brackets in the wrong spot. Try Stream.<String> empty().findFirst())

If in a class implements an interface and at the same extends another class, can we declare a constructor for the class with super keyword? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
The compiler is not accepting the constructor as a constructor but as a method and giving the following remark:
My piece of code:
class Rsesults extends Mark implements Sports {
Results(int x,int y) {
super(x,y);
}
The error:
invalid method declaration; return type required
Results(int x, int y)
Your class and your constructor have different names : Rsesults - Results
Which means that Java doesn't recognize Results as constructor, but thinks that it's a general method ( which means it has to have a return type )

NoSuchMethodException in Intellij in basic project [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I just started to learn Java and I want to use Intellij however I'm not able to run any project(even a simple Hello World). I always get this Exception.
Please follow proper syntax for the main method . .
public static void main(String[] args) {
//Your code
}
You have used method name as Main change it to main it will work.
You have a typo in the method name. It must be 'main' always because Java is case sensitive and JVM always looks for a 'main' method to run.
Try this:
public static void main(String[] args) {...}

Categories

Resources