-2

I have below class.

public class A {
    private String name;
    private String age;
    //getters and setters
}

public class B extends A {
    // Some setters and getters
}

public class C extends B {
    // here can i access name and age properties using public getters of A ?
}

Can I access A class members in Class C ?

Thanks!

Charles Goodwin
  • 6,402
  • 3
  • 34
  • 63
user755806
  • 6,565
  • 27
  • 106
  • 153

1 Answers1

1

The answer, as per the example, is no. The class members are marked as private thus are private to A.

Either use getters and setters, or change the visibility using protected or public.

You are getting voted down because you have not tried the code before posting it, and it is not a constructive question (it's a yes/no question which is not what the SO format is designed for).

Charles Goodwin
  • 6,402
  • 3
  • 34
  • 63