Question: public class Animal { private String name; //line 1 private int weight; //line 2 private String getName(){ return name; } //line 3 public int fetchWeight(){

public class Animal { private String name; //line 1 private int weight; //line 2 private String getName(){ return name; } //line 3 public int fetchWeight(){ return weight; } //line 4 } public class Dog extends Animal { private String food; //line 5 public void mystery(){ System.out.println("Name = " + super.getName()); //line 6 System.out.println("Food = " + food); //line 7 } }

I got error message for this code: Don't know what is wrong with it..

----jGRASP exec: javac -g Animal.java Animal.java:11: error: class Dog is public, should be declared in a file named Dog.java public class Dog extends Animal { ^ Animal.java:14: error: getName() has private access in Animal System.out.println("Name = " + super.getName()); //line 6 ^ 2 errors ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!