Results 1 to 6 of 6
  1. #1
    cew27 is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default packages problem

    right i have been trying to make the simplest subclass in my package but i cant seem to get it to work,
    i have lost the source file i was using so could someone please make a source file for a simple bit of code called extendscew
    all it is is

    package hello.1.stuff;
    public class extendscew{

    public static void main(String args[]) {
    string hello123 = ("hello 1");
    system.out.println (hello123);
    }
    }

    then another class that extends that
    package hello.1.stuff

    class extendscew1 extends extendcew {
    public static void main(String args[]){
    string hello123 = ("hello2")
    system.out.println (hello123);
    }
    }


    this is just a rough outline and is not syntax correct but when i try to make this i get a no class defound error so could someone please make the same simple 2 source files so i may compair them to mine when i find them and pinpoint the problem
    greatly appreatiated

  2. #2
    Cazrin is offline Member
    Join Date
    Dec 2007
    Posts
    16
    Rep Power
    0

    Default

    Try:
    Java Code:
    package hello.1.stuff;
    
    public class extendscew{
    
    public extendscew() { } // This is the line I've inserted
    
    public static void main(String args[]) {
    
    string hello123 = ("hello 1");
    system.out.println (hello123);
    
    }
    }
    You said it was a rough outline so I don't know if that's actually included in your source code.

    Also on the extending class you don't have a ; at the end of your package hello.1.stuff or string hello123 = ("hello2") lines.

  3. #3
    cew27 is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    thanks for the reply :D

    ok one more problem here is the code
    this is the first piece of code called oriigin that i will extend but at the moment i cant compile it because it says that a ; is expected at the end of the packages line?
    Java Code:
    package hello.1.stuff;
    
    public class origin{
    
    public static void main(String args[]) {
    
    string hello123 = ("hello 1");
    system.out.println (hello123);
    
    }
    }

  4. #4
    jelly's Avatar
    jelly is offline Member
    Join Date
    Jan 2008
    Location
    Somerset, UK
    Posts
    46
    Rep Power
    0

    Default

    Each component part of a package name must conform to identifier naming rules, in particular this means they must start with a letter.

    hello.1.stuff is invalid as the component '1' breaks those rules

    hello.stuff or hello.s1.stuff would be valid.
    -- Hope that helps

  5. #5
    cew27 is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    cheers for that i will give it a go tonight :D

  6. #6
    cew27 is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    right i dont know if i am doing this right or if i am following the rules of java but i cannot compile the code that extends the original
    origin:
    Java Code:
    package com.google.stuff;
    
    
    public class origin {
    	public origin() { }
    
    	public static void main(String args[]) {
    
    int hello123 = 32;
    int hello1234 = 32;
    System.out.println(hello123 + hello1234);
    	}
    }
    extention:
    Java Code:
    package com.google.stuff;
    
    
    public class extentionorigin extends origin{ 
    
    
    	public static void main(String args[]) {
    
    int hello123 = 233;
    System.out.println(hello123 + hello1234);
       }
    }
    this is probably way off the mark but all help is greatly appreciated, i have been stuck on this issue for months

Similar Threads

  1. Replies: 3
    Last Post: 02-12-2008, 11:03 AM
  2. Using packages
    By prfalco in forum New To Java
    Replies: 5
    Last Post: 01-31-2008, 10:38 PM
  3. Closing packages
    By uncopywritable in forum New To Java
    Replies: 0
    Last Post: 08-13-2007, 11:47 PM
  4. packages
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 12:10 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
  •