O'Reilly Forums: Reference Variable Declaration - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Reference Variable Declaration

#1 User is offline   Saumyaraj 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 20-September 12

Posted 20 September 2012 - 05:26 AM

I am aware of the essence of polymorphism i.e I can declare a reference variable of type superclass and assign it to a subclass object but why i am not able to declare a reference variable of type subclass and refer it to superclass object....plzzz help
package confusion;
class Sup
{    
    void print()
    {
    System.out.println("hello");
    }
}
public class Sub extends Sup
{
    public static void main(String[] args)
    {
  Sub ob= new Sup();
  ob.print();
    }
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users