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 } 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 }

Question: I got this error. I want to access the super class data; name.

----jGRASP exec: javac -g Animal.java Animal.java:14: error: getName() has private access in Animal System.out.println("Name = " + super.getName()); //line 6 ^ 1 error

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!