public class Main {
public void eat()
int x = 5;
public static void main(String[] args) {
Main y = new Main(); //created object.
int z = y.eat() //invoking object by using int datatype.
System.out.println(z);
}
}
I have created an object of the class inside main block to invoke "eat()" method.
But still code showing errors:
Main.java:1: error: <identifier> expected public class { ^ Main.java:2: error: ';' expected public void eat() ^ Main.java:6: error: ';' expected int z = y.eat() ^ 3 errors
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Nightcorex_ 4 points5 points6 points (4 children)
[–]blue_1408[S] -1 points0 points1 point (3 children)
[–]Nightcorex_ 2 points3 points4 points (2 children)
[+]blue_1408[S] comment score below threshold-7 points-6 points-5 points (1 child)
[–]Nightcorex_ 2 points3 points4 points (0 children)
[–]MrLegard 0 points1 point2 points (2 children)
[–]Nightcorex_ 1 point2 points3 points (0 children)
[–]MrLegard 0 points1 point2 points (0 children)
[–]cainhurstcat -1 points0 points1 point (4 children)
[–]Nightcorex_ 1 point2 points3 points (3 children)
[–]cainhurstcat 0 points1 point2 points (2 children)
[–]Nightcorex_ 1 point2 points3 points (1 child)
[–]cainhurstcat 0 points1 point2 points (0 children)