Results 1 to 3 of 3

Thread: [RESOLVED] inheritance - a beginner's question

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    183

    [RESOLVED] inheritance - a beginner's question

    Ello,

    If class "widget", extends "something", is it possible to create an instance of something then use it it as a widget?

    Here's the code I'm trying to get to work:

    VB Code:
    1. class universe
    2. {
    3.     public static void main(String[] args)
    4.     {
    5.         something whoKnows;
    6.         whoKnows = new widget();
    7.         System.out.println(whoKnows.getWeight());
    8.     }
    9. }
    10.  
    11. class something
    12. {
    13.     public int weight=2;
    14.    
    15. }
    16.  
    17. class widget extends something
    18. {
    19.     public int getWeight()
    20.     {
    21.         return weight;
    22.     }
    23. }

    Output:
    C:\JAVA\INHERI~1>javac universe.java
    universe.java:8: cannot find symbol
    symbol : method getWeight()
    location: class something
    System.out.println((widget)whoKnows.getWeight());
    ^
    1 error
    Thanks!
    Last edited by Evil_Cowgod; Apr 19th, 2006 at 03:38 AM.
    When you ask a question, try and answer a few

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width