Results 1 to 5 of 5
  1. #1
    c_walker is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

    Default Scope Problem???

    Guys, I need your help again.

    I think it's about SCOPES (w/ abstract classes, interfaces and inheritance). We are required to put all of our classes in a single file, that file compiled but when I tested it, it complained that "cannot find symbol - class Rt". That's why, I created another version in which there is a file/class, when I used the same tester to test it, it worked.

    Here's a sample of my codes:

    Java Code:
    public class Family {
          abstract class Rt
          {
              String name;
              int years;
          public Rt (String n, int a)
            {
                name = n;
                years = a;
            }
            public void printN()
            {
                System.out.println(name);
            }
            public void printYrs()
            {
                System.out.println(years);
            }
        }
        
        abstract class Sb extends Rt
        {
            public Sb (String n, int a)
            {
                super(n, a);
            }
            public abstract void food();
            public void talk()
            {
                System.out.println("Howdy?");
            }
        }
        
        class Bro extends Sb
        {
           public Bro (String n, int a)
           {
               super(n, a);
           }
           public void food()
           {
               System.out.println("curry");
           }
           public void printN()
           {
               System.out.println("Guess what?");
           }
        }
     ...........
    
    }
    Here's my tester:

    Java Code:
    public class Tester {
            
       public static void main (String args[])
       {
           Rt r = new Bro("Allan", 25);
           Sb s = new Bro("Pete", 10);
           r.printN();
           r.printYrs();
           s.talk();
           s.printN();
           s.printYrs();
           s.food();      
           
        }
    }
    I do not know where I made mistakes or maybe there's something lacking in my codes. Hope you can help me :confused:.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your classes are buried within Family.

    Java Code:
    public class Tester {
    
       public static void main(String args[]) {
          Family.Rt r = new Family().new Bro("Allan", 25);
          Family.Sb s = new Family().new Bro("Pete", 10);
          r.printN();
          r.printYrs();
          s.talk();
          s.printN();
          s.printYrs();
          s.food();
    
       }
    }

  3. #3
    c_walker is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

    Default

    wow, thank you very much sir but is there anything I can add/modify with my Family class since I am not the one who's going to test my program? My tester will not really be used, I just created it so that I can test my program myself.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Everything will depend on the specific requirements of your project.

  5. #5
    c_walker is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

Similar Threads

  1. Problem with Session Scope while using with Java Bean
    By sulthanmytheen in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-27-2009, 10:50 AM
  2. Variable Scope
    By Laura Warren in forum New To Java
    Replies: 3
    Last Post: 01-11-2009, 10:16 PM
  3. [SOLVED] scope problem with a servlet
    By pnolans in forum Java Servlet
    Replies: 7
    Last Post: 08-23-2008, 02:50 PM
  4. jsf scope query
    By nc_newie in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 08-06-2008, 02:34 PM
  5. return out of scope?
    By another_steve in forum New To Java
    Replies: 5
    Last Post: 01-28-2008, 09:34 PM

Posting Permissions

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