0

case 1.

class A extends java.util.ArrayList
{

    public static void main(String[] args)
    { 

        ArrayList a=new ArrayList();
    }

}

Here I am getting a compiletime error saying,

  cannot find symbol 
         
  Symbol:class ArrayList 
   
  location:class A

case 2.

class A extends java.util.ArrayList
{

}

This one is compiling successfully.

Then what's the need of extending ArrayList class? If we can't make use of it (as in case 1)?

Laurel
  • 5,965
  • 14
  • 31
  • 57
  • First, format your code, currently it's unintelligible. Secondly, both cases extend `java.util.ArrayList`, i don't see any difference. – Chaosfire Jun 14 '22 at 15:42
  • Extending a class is not the same as importing it. – VGR Jun 14 '22 at 15:47

1 Answers1

0

Based on my understanding of your question, you would like to use fully qualified name against import.

The reason you are getting error in first case is because you missed to mention fully qualified class name while doing:

ArrayList a=new ArrayList();

Each time you are declaring ArrayList object in this scenario, you have to use fully qualified name.

Reference : https://docs.oracle.com/javase/tutorial/java/package/usepkgs.html

Ashish Patil
  • 4,428
  • 1
  • 15
  • 36