padmavathi gangasani wrote:
What is the difference between extending a class and using super class methods and creating objects for the class,using object to invoke a method.
It's a design issue. You don't extend a class to be able to use its methods. You extend a class when you're creating a specialized type of whatever that class represents. Inheritance is much overused, especially by beginners but also by experienced developers. You should rarely extend concrete classes.
How memory will be allocated in both terms
The memory for the member variables is the same. The basic object overhead is 1 vs. 2. However, you will NOT be using memory concerns to decide whether to extend or not.
adn why proteced modifier access for subclass and non subclass(using object to invoke protected method)in different packaes.
If B extends A, then an object of type B will also contain all the member variables that are in class A. An object of type B is an object of type A, with extra member variables and methods added (those that are defined in class B).