0

Let's say we have package a and package b, both have many classes, all public.

Now class Cat from package a wants to extend class Animal from package b, is this inheritance legal?

acdcjunior
  • 132,397
  • 37
  • 331
  • 304
Raj
  • 101
  • 1
  • 1
  • 5

2 Answers2

2

ASure, just import the parent class and extend it.

package a;

import b.Animal;

public class Cat extends Animal {

}

You can skip the import and use the fully qualified class name for Animal as well. But messier.

CBass
  • 983
  • 6
  • 11
0

Yes. Packages make grouping classes convenient, and non-public and non-private methods and fields are only visible to other members of the same package

rolfl
  • 17,539
  • 7
  • 42
  • 76