Is a class a subclass of itself?

hello experts,
Is a class a subclass of itself?
every class inherits Object class. i heard somewhere that
A class is a subclass of itself. But i dont know how is it?
Can anyone clarify me doubt?
Regards,
SRI.

Java_Aspirant wrote:
hello experts,
Is a class a subclass of itself? no
every class inherits Object class. i heard somewhere that
A class is a subclass of itself. But i dont know how is it?it's wrong. Whoever said that either wasn't talking about Java or didn't know what he was blabbing about (or both).
>
Can anyone clarify me doubt?
aya hef no dbt but dis.

Similar Messages

  • Is a class is subclass of itself?

    is a class is subclass of itself?

    A class is never a Sub class of itself..
    can you do like this...
    Class Sample extends Sample
    public static void main(String args[])
    System.out.println("Hello...");
    no way doing like this.....
    ok You got it, I think
    One thing
    Subclass concept is : The private members of the super class cannot be accessed in the subclass and here the super class and sub class are same. then it wont work.......
    ok
    Edited by: sankar.natukula on Sep 24, 2007 2:04 AM

  • Can a class b subclass of itself wh is diff between instaceof n isInstance

    appricate your views

    Okay. After reading it three times, I got you. Impoliteness abounds.
    No, classes cannot extend themselves.
    1) It should be obvious if you put a little thought of your own into it. Why should it be able to?
    2) You could have simply wrote some code to try this yourself.
    instanceof is an operator. I have no idea what isInstance is supposed to be.
    madeaboutjava, you're leeching knowledge, make no useful contributions to this board whatsoever, show no effort or even will to learn anything by yourself rather than being spoonfed by us and basically can be considered a big waste of time. I will no more reply to you.

  • Is a class subclass of itself

    reply for the subject que

    Nice find, Jenny. :o)
    Despite the fact that the quote comes from Sun, I'm not sure that it's in line with the JLS, to wit:
    The subclass relationship is the transitive closure of the direct subclass relationship. A class A is a subclass of class C if either of the following is true:
    * A is the direct subclass of C.
    * There exists a class B such that A is a subclass of B, and B is a subclass of C, applying this definition recursively.
    I haven't found in the JLS where they use the term "strict subclass", or the implied "non-strict" subclass. The JLS only uses the term "subclass" in the context mentioned above. Furthermore JLS is quite clear that a final class cannot have a subclass, which would seemingly preclude a final class from being a subclass of itself.
    But, hey, if that's what Sun says the certification is asking for, I'd take their word for it over mine... :o)

  • Super class and subclass

    While creating an instance for the subclass
    will there be any instance created for the superclass
    internally ??

    Depends what you mean by "internally".
    Suppose you have
    class A
        int aaa;
    class B extends A
        int bbb;
    }and you do
    B myB = new B();then, conceptually at least, you get a reference to an instance of B that looks like this:
        aaa          The value of aaa in A
        bbb          The value of bbb in BThat is, the single instances contains data for both A and B.
    Sylvia.

  • Class vs subclass

    What is the purpose of a subclass and when should a subclass be used?

    You have a basic class "Box", but you need a more specific box, say a wooden toy box, you extend class Box and make your own subclass "WoodenToyBox" that has the funtionality of the original box plus the added features that you write into the subclass.

  • Subclass Vs Concrete class

    Hi,
    What is the exact difference between subclass and concrete class?
    What is the need in subclassing abstract class to again abstract class?
    Thanks in Advance,
    venu.

    Hi,
    What is the exact difference between subclass
    and concrete class?"Subclass" defines a class' relationship to another class.
    class A extends BB is a subclas of A.
    Every class in Java except Object is a subclass of some other class.
    A concrete class is one that is not abstract.
    class A {}
    abstract class B{}Cass A is concrete. Class B is not.
    A class can be both a subclass and concrete. In fact, every single concrete class except Object is a subclass.
    What is the need in subclassing abstract class to
    again abstract class?You would do that when you're able to provide concrete implementations for some but not all of the abstract methods

  • Subclass UIScrollView with Custom Class

    I want to use my custom class "ImageGridView" (subclass of UIScrollView) in Interface Builder.
    Here is what I have done:
    1) Dragged a UIScrollView onto my main view in IB.
    2) Changed the new UIScrollView Class Identity to "ImageGridView" which autocompleted so I thought it should work if it found it no prob.
    3) Placed an NSLog(@"HIT") in the init of the ImageGridView code.
    4) Also tried debugging break in the ImageGridView
    No luck....i can't get the custom class to instantiate .....no code is even run in that class.

    Don't forget that the class will be instantiated within Interface Builder and 'saved' within the NIB. At runtime it is unsaved with all of the initialised parameter values intact.
    Try using the 'viewDidLoad' (??I think this is the name - going by memory here) method which is called after the view has been restored from its saved state in the NIB.
    Susan

  • Accessing protected and private data of a class

    Hi friends,
    I have writen a sample code in oops abap but iam facing some problem.
    CLASS MAIN DEFINITION.
        public SECTION.
          DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
          METHODS : PUBLIC.
      ENDCLASS.
      CLASS MAIN IMPLEMENTATION.
         METHOD : PUBLIC.
           WRITE : /5 VAR1.
              VAR1 = 'CHANGED'.
           WRITE : /5 VAR1.
         ENDMETHOD.
      ENDCLASS.
    START-OF-SELECTION.
        DATA :
               O_MAIN TYPE REF TO MAIN.
               CREATE OBJECT O_MAIN.
               CALL METHOD O_MAIN->PUBLIC.
    now its working fine as public methods can be access by all the people where as protected methods can be access by class and subclass so i can inherit the properties of above class and access the protected data.
    where as to access private data , private data can be access by class itself...
    so now how do i access the private data within the class...ie : how do i get the above output when i use a private section instead of public..
                CLASS MAIN DEFINITION.
        private SECTION.
          DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
          METHODS : Private.
      ENDCLASS.
      CLASS MAIN IMPLEMENTATION.
         METHOD : Private.
           WRITE : /5 VAR1.
              VAR1 = 'CHANGED'.
           WRITE : /5 VAR1.
         ENDMETHOD.
      ENDCLASS.
    START-OF-SELECTION.
        DATA :
               O_MAIN TYPE REF TO MAIN.
               CREATE OBJECT O_MAIN.
               CALL METHOD O_MAIN->Private.
    iam getting a error saying you cannot access the private section...
    now private section can be accessed within the class but nt by others...
    to access the private section within the class how should i correct it...
    Regards
    kumar

    HAI,
    Private attributes or methods can be accessed directly by the Object but within the Scope of the Class, but not outside.
    Look at this:
    CLASS MAIN DEFINITION.
    public  SECTION.
    METHODS : Public.
    private SECTION.
    DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
    METHODS : Private.
    ENDCLASS. " END of CLASS DEFINITION
    CLASS MAIN IMPLEMENTATION.
    METHOD : Public.
    CALL METHOD Private.
    ENDMETHOD.
    METHOD : Private.
    WRITE : /5 VAR1.
    VAR1 = 'CHANGED'.
    WRITE : /5 VAR1.
    ENDMETHOD.
    ENDCLASS. " END of CLASS IMPLEMENTATION
    START-OF-SELECTION.
    DATA:  O_MAIN TYPE REF TO MAIN.
    CREATE OBJECT O_MAIN.
    CALL METHOD O_MAIN->Public.
    PS: If there is any better alternative solution please share it .
    Best Regards,
    rama

  • Reflection: Gather info about Subclass Fields

    I have a system that works as follows:
    I have written an abstract base class (say ClassA) to be used in an application I am developing. The intention is that another programmer may come and subclass ClassA several times, creating different versions.
    In the subclasses, I would expect there to be an arbitrary number of objects of another class, ClassB. I need to be able to perform a method from ClassA on each and every object of ClassB.
    In order to make the designing of the subclass easier, I would like to be able to call a single method of ClassA that would inspect itself to find all the objects of ClassB, rather than forcing the other programmer to call the method of ClassA for EACH object.
    THE PROBLEM:
    When I obtain this.getClass() from within ClassA, the fields of the class object come up NULL. It seemingly has no fields, constructors, methods, etc. The Class object itself is not null, but it's fields are.
    Can anyone explain to me why this is? Can anyone suggest a solution to me?

    Here's a quick example of what I had in mind based on the information provided. Caveat: it has a high likelihood of not meeting your exact requirements.
    abstract class ClassA {
        void perform() {
            for (ClassB b : getBs()) b.specialMethod();
        public abstract void add(ClassB cb) { }
        protected abstract Collection getBees() { }
    class SubclassOfA extends ClassA {
        private Collection<ClassB> bees = new ArrayList<ClassB>();
        public void add(ClassB bee) {
            bees.add(bee);
        protected Collection getBees() {
            return Collections.unmodifiableCollection(bees);
    interface myInterface {
        void specialMethod();
    /** Arbitrary Object **/
    class ClassB implements myInterface {
        public void specialMethod() { }   
    }

  • How to load parent Class like this?

    I have a java application that use another class in a jar file. And there is a class in the application's main class extends the class in the jar file. I have packaged the application into a jar file.
    the directory structure :
    foder [dist] : app.jar [lib]
    foder [lib]: Library.jar
    (I excute "java" cmd in folder "dist" )
    Now i can run it, if i use command line option -Xbootclasspath/a:
    "java -Xbootclasspath/a:lib/lib.jar -jar app.jar"
    (Because if i use "java -jar ", "-cp .;lib/Library.jar" option have no effect.)
    But I don't konw how make it run by codes.I tried this:
    Main.javapackage myapp;
    java.net.URL liburl = new java.io.File("lib\\Library.jar").toURL();
    java.net.URLClassLoader loader =
            new java.net.URLClassLoader(new java.net.URL[] { liburl });
    Class c = loader.loadClass("mylib.parentclass");
    Object    parentobj = c.newInstance();
    //c = loader.loadClass("myapp.subclass");  //can't run
    //Object    subobj  = c.newInstance();
    subclass.javapackage myapp;
    subclass extends parentclass{
    }parentclass.javapackage mylib;
    public class  parentclass{
    }the code Object    parentobj = c.newInstance(); can excute without problem . parentclass's constructor excuted.
    but
    c = loader.loadClass("myapp.subclass");
    Object    subobj  = c.newInstance();can not excute and without any exception throw out.
    I used the "-verbose:class" option , the output is:
    [Loaded java.lang.ClassFormatError from shared objects file] <---the last line
    Thanks for reading and participating .
    Please help me or point me to resources where I can read .
    Sorry for my poor english.
    thanks a lot .

    The problem is that when a class wants to resolve a reference to another class (e.g. when a class fetches it's parent) it uses the classloader that loaded it, which is not necessarilly the classloader from which it was requested.
    When you ask a standard classloader (e.g. URLClassLoader) for a class the first thing it tries is asking it's parent class loader. Only if the parent doesn't find the class does it try itself.
    So, if a class is available to the system ClassLoader then even though you ask a URLClassLoader for it, it's the system ClassLoader which actually loads it and, hence, it's the system ClassLoader that class uses to resolve any references.
    ClassLoaders generally form a kind or heirarchy and references can be made towards the root of the ClassLoader tree, but not in the other direction.
    You would have to do something like have a small main class which sets up the classloader and make your real main class available only on the jars that the URLClassLoader adds to the classpath. That way the main class will have the URLClassLoader as its ClassLoader and will use it to get it's parent class.

  • Whats the difference between these types of classes?

    What's the difference between using a "private inner class", an "anonymous inner class", and a "class that implements on itself" to create a GUI?
    Also, what's the difference between regular classes, abstract classes, and interfaces?
    I ask because I'm an excellent coder, but have trouble understanding the terminology behind the code and also explaining the code.

    hi,
    First of all your questions are beyond the scope of this forum ...
    They are much general about the java syntax of oop.
    So read tutorials about the java programming language.
    http://en.wikipedia.org/wiki/Java_syntax
    Olek

  • Declaring top level classes instead of subclasses

    I seem to have misunderstood something very basic.
    It's always better, where possible, to declare the top-level class instead of the sub-class, right?
    Ok, then why do I have the following problem?
    I declare, from the JavaMail API the following:
    Message theMessage = new MimeMessage(session);instead of declaring directly the subclass like this:
    MimeMessage theMessage = new MimeMessage(session);but when I use a method which is only found in the MimeMessage class I get a compile error.
    [javac] 189.           theMessage.setSubject(subject, "iso8859_1");
    [javac] <-------------------------------->
    [javac] *** Error: No match was found for method "setSubject(java.lang.String, java.lang.String)".
    Have I really misunderstood something so basic?? Surely the compiler knows that theMessage is an instance of MimeMessage??
    Any clear explanation to explain why I get this compile error would be gratefully received. I have been faithfully declaring top-level classes instead of subclasses in my code, but if the compiler doesn't let you do so, then what's the point?

    Ok, my confusion was started by an article on the
    Collection classes which stated that:
    Map theMap = new HashMap(); was better
    programming practice.
    Yep.
    But the Map class is an Interface, right? - Whereas
    Message is a normal class with subclass MimeMessage.
    I think that's where my confusion started.Well, this isn't really a class vs. interface difference. It goes to which class (or interface) is the "highest" (closest to Object) and still has all the public interface you need.
    There are cases where you'll declare a variable to be of a base class type like Message.
    You just need to get into the habit of separating the left side of the = from the right side. On the left, you put the bare minimum that completely meets your needs. You say, "I need a List" or "I need a Map" or "I need a SortedMap" (a subinterface of Map) or "I need a Message" or "I need a MimeMesage".
    Then, on the RHS =, you decide which particular class best implements the public interface that you said you need (by declaring it on the LHS). "For my Map, I'll use a HashMap." "For my Message, I'll use a MimeMessage." "For my MimeMessage, I'll use a MimeMessage".

  • LoadClass    (error loading a class which extends other class  at run-time)

    Hey!
    I'm using the Reflection API
    I load a class called 'SubClass' which exists in a directory called 'subdir' at run-time from my program
    CustomClassLoader loader = new CustomClassLoader();
    Class classRef = loader.loadClass("SubClass");
    class CustomClassLoader extends ClassLoader. I have defined 'findClass(String className)' method in CustomClassLoader.
    This is what 'findClass(String className)' returns:
    defineClass (className,byteArray,0,byteArray.length);
    'byteArray' is of type byte[] and has the contents of subdir/SubClass.
    the problem:
    The program runs fine if SubClass does not extend any class.
    If however, SubClass extends another class, the program throws a NoClassDefFoundError. How is it conceptually different?
    Help appreciated in Advance..
    Thanks!

    Because i'm a newbie to the Reflection thing, i'm notI don't see reflection anywhere. All I see is class loading.
    sure what role does the superclass play when i'm
    trying to load the derived class and how to get away
    with the errorWell... hint: all the superclass's stuff is not copied into the subclass.
    I am quite sure it fails to load the superclass because of classpath issues.

  • What is the difference between document class and normal class

    Hi,
    Please let me know what is the difference between document class and normal class.
    And I have no idea which class should call as document class or call as an object.
    Thanks
    -Actionscript Developer

    the document class is invoked immediately when your swf opens.  the document class must subclass the sprite or movieclip class.
    all other classes are invoked explicitly with code and need not subclass any other class.

Maybe you are looking for

  • NFe Fiscal Workplace - Não atualiza com Status Sefaz

    Boa noite! Estou tentando reexecutar a consulta de status de NFe através do fiscal workplace para algumas NFes que ficaram com Status Global 11 devido a um problema temporário que tivemos com SSL (certificado estava sendo rejeitado pela SEFAZ) . Para

  • Logic board failure on Mac Book Pro. Backed up info via time machine with sea gate external hard drive. Help!

    I now have no access to any mac now, and the old mac while it still has my old information freezes immeadiatley upon starting. I am therefore switching to PC laptop that has be graciously given to me. My question is how do I get my information off my

  • Camera Raw 6.0 (and Lightroom 3) extra slow, what's happening ?

    Hi, I'm having a very annoying issue with both CR 6.0 and LR 3 which is a very slow responsiveness in the photo previews. A month ago, I was using Windows XP SP3 32bit on my machine (Intel Core Duo Q6600 (4x2.57Ghz cores) - 4Gb RAM). I had Photoshop

  • Test a procedure which returns a sys_refcursor

    Hi all, Oracle 9i Got a simple stand alone procedure which has an input param and an output param, the second of which is a ref cursor. Can anyone tell me how I can go about testing this from within Pl/SQL (Command line)? CREATE OR REPLACE PROCEDURE

  • Wacom GD-0912-U driver for Mac OS X 10.9.1

    Hi-- Trying to use my Wacom GD-0912-U with Aperture Need a driver for Mac OS X 10.9.1 (afraid to update to Yosemite :>)) Have been through Wacom community and tried with no luck W 6.1.5-2 6.3.7-3 6.3.9 w3 Anyone here able to help? Thanks for your tim