Superclass and subclass

Ok I have now reached the area of using Superclass and subclass in my
self study of Java, and I am stumped on what is I am sure is a very
easy concept. Here's the Scenerio. I have three classes Point, Circle
and InheritanceTest. Point is the Superclass that is being referenced
from Circle InheritanceTest has the main Method.
Inside the Point class the book I am using has this note inside the
constructor.
public void Point{
//implicit call to superclass constructor occurs here
setPoint(0,0);
My question is this, Is the call to it's self or the object class?
And do you Know which one it is referring to?
Thanks in advance

public void Point{
//implicit call to superclass constructor occurs here
setPoint(0,0);
}When you extend a class, every constructor of the new class must call a constructor of the extended class- this is done by using super() or super(some arguments). Note that if you don't put this in, java will implicitly call super() for you- it basically inserts this call into your new constructor.
As for the setPoint() method, if your new class has a method of this name and signature (i.e. same type of arguments), it will call your sub-class's method. If the sub-class does not have a method like this defined, it will look for this method in the super-class and call that one. In this way, you are inheriting the methods of the super-class. Unless you specifically override a method (give a method of the same name in type in the sub-class as in the super-class), all public or protected methods of the super-class can be used as if they were methods of your sub-class.
Check this out:
public class SuperClass
     private int value = 0;
     public SuperClass()
          super();
          // Calling the default constructor of Object, the superclass of this class
     public SuperClass(int value)
          // Implicitly calling super() since a superclass constructor was not given explicitly
          this.value = value;
     public int getValue()
          return value;
     public void setValue(int value)
     this.value = value;
     public void changeValue()
          setValue(getValue() + 1);
public class SubClass
     public SubClass()
          super(0);     // Calls the SuperClass(int) constructor
     public SubClass(int value)
          // Implicit call to SuperClass() constructor
          setValue(value);
     public void changeValue()
          // Overrides the SuperClass method of the same name
          setValue(getValue() - 1);
     public void useSuperChangeValue()
          super.changeValue();     // Calls SuperClass.changeValue()
     // If you want to use the super-class methods, even if they have been overridden,
     // use the keyword "super" to reference the superclass

Similar Messages

  • Superclass and subclass and abstract method

    Hi all,
    I am a little bit confused about abstract methods.
    I define a superclass without abstract keyword and an abstract method inside the superclass. Then I write a subclass to extend the superclass.
    When I compile the source code I get error. It looks like I can't initiate an instance from the supercalss and/or subclass. If I put abstract key word in the superclass definition there is no problem at all. So my question: does abstract method needed to be defined in an abstract superclass only?
    Thank for you input.

    Abstract methods can only be declared in an abstract class.

  • What's wrong on the superclass and subclass

    Dear all,
    The drawing panel cannot draw the figures, what's wrong?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class CustomPanel1 extends JFrame { 
    private final String list[] = { "Circle", "Square", "Triangle"};
    private FlowLayout layout1, layout2, layout3;
    private DrawShape drawPanel;
    private JButton clearButton;
    public static JLabel label;
    private JComboBox shapeList;
    private JTextField textField1, textField2;
    public static int size;
    // set up GUI
    public CustomPanel1() {   
    // create custom drawing area
    drawPanel = new DrawShape(this);
    // set up ClearButton
    clearButton = new JButton( "Clear" );
    // add the ActionListeber
    clearButton.addActionListener(
    new ActionListener() { // anonymous inner class
    // handle action perform event
    public void actionPerformed( ActionEvent event ) {        
    // clear originList
    drawPanel.originList.clear();
    drawPanel.area = 0;
    drawPanel.perimeter = 0;
    label.setText("Area " + drawPanel.area +
    " Perimeter " + drawPanel.perimeter );
    repaint();
    }// end handle
    } // end anonymous inner class
    ); // end call to addActionListener
    //set up combox
    shapeList = new JComboBox(list);
    shapeList.setMaximumRowCount(3);
    //add ItemListener
    shapeList.addItemListener(
    new ItemListener(){
    // handle item state change event
    public void itemStateChanged (ItemEvent event) {                  
    if(event.getStateChange() == ItemEvent.SELECTED){
    // draw circle
    if( shapeList.getSelectedIndex() == 0){           
    DrawCircle.shape = 0;
    DrawCircle.draw(DrawCircle.Circle);
    } // end if
    // draw square
    else if ( shapeList.getSelectedIndex() == 1) {           
    DrawShape.shape = 1;
    DrawSquare.draw( DrawSquare.Square);
    } // end if
    // draw triangle
    else if ( shapeList.getSelectedIndex() == 2) {           
    DrawShape.shape = 2;
    DrawTriangle.draw( DrawTriangle.Triangle);
    } // end if
    } // end if
    } // end handle
    } // end anonymous inner class
    ); // end call to addActionListener
    // set up parameter panel containing parameter
    JPanel parameterPanel = new JPanel();
    layout1 = new FlowLayout();
    parameterPanel.setLayout(layout1);
    parameterPanel.setBackground( Color.PINK );
    layout1.setAlignment( FlowLayout.CENTER);
    parameterPanel.add( new JScrollPane(shapeList));
    parameterPanel.add( clearButton );
    // set up the text Panel and textfield
    JPanel textPanel = new JPanel();
    layout3 = new FlowLayout();
    parameterPanel.setLayout(layout3);
    textPanel.setBackground( Color.PINK );
    layout3.setAlignment( FlowLayout.CENTER);
    textField1 = new JTextField( "Size");
    textField1.setFont(new Font("Serif",Font.BOLD,14));
    textField1.setEditable (false);
    textField2 = new JTextField( "",6);
    textField2.setFont(new Font("Serif",Font.BOLD,14));
    // add ActionListener
    textField2.addActionListener(
    new ActionListener(){
    // handle action perform event
    public void actionPerformed (ActionEvent event) {         
    JTextField field = (JTextField)event.getSource();
    String entry = field.getText();
    size = Integer.parseInt(entry);
    } // end handle
    } // end anonymous inner class
    ); // end call to addActionListener
    textPanel.add(textField1, BorderLayout.NORTH);
    textPanel.add(textField2, BorderLayout.SOUTH);
    // set up the combine panel of parameterPanel and textPanel
    GridLayout gridLayout = new GridLayout();
    gridLayout.setRows(2);
    gridLayout.setColumns(1);
    JPanel combinPanel = new JPanel();
    combinPanel.setBackground( Color.PINK );
    combinPanel.setLayout(gridLayout);
    combinPanel.add(parameterPanel, BorderLayout.NORTH);
    combinPanel.add(textPanel, BorderLayout.SOUTH);
    // set up datapanel conaining data
    JPanel dataPanel = new JPanel();
    layout2 = new FlowLayout();
    dataPanel.setLayout(layout2);
    dataPanel.setBackground( Color.PINK );
    label = new JLabel ("Area " + drawPanel.area + "Perimeter " +
    drawPanel.perimeter, SwingConstants.CENTER);
    dataPanel.add( label);
    // attach button panel & custom drawing area to content pane
    Container container = getContentPane();
    container.add( combinPanel, BorderLayout.NORTH);
    container.add( drawPanel, BorderLayout.CENTER );
    container.add( dataPanel, BorderLayout.SOUTH );
    setSize( 500, 500 );
    setVisible( true );
    } // end constructor CustomPanelTest
    // main
    public static void main ( String args[] ) {   
    CustomPanel1 app = new CustomPanel1();
    app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } // end main
    } // end class CustomPanelTest
    // A customized JPanel class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    class DrawShape extends JPanel {
    public final static int Circle = 0, Square = 1, Triangle = 2;
    public static int shape;
    public int xPos,yPos;
    java.util.List originList;
    public int count = 0;
    public static double area ;
    public static double perimeter ;
    final double pi=3.141592;
    CustomPanel1 client;
    boolean shapeWasCreated = false;
    public DrawShape(CustomPanel1 customer){     
    this.client = customer;
    // set up the list of shape to draw
    originList = new ArrayList();
    // set up mouse listener
    addMouseListener(
    new MouseAdapter() {  // anonymous inner class
    // handle mouse press event
    public void mousePressed( MouseEvent event )
    xPos = event.getX();
    yPos = event.getY();
    originList.add(count, new String(
    shape + "." + xPos + "," + yPos + "*" + CustomPanel1.size ));
    // set to draw ready
    shapeWasCreated = true;
    repaint();
    } // end handle
    } // end anonymous inner class
    ); // end call to addMouseListener
    } // end method
    } // end class
    // A customized JPanel class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class DrawCircle extends DrawShape {
    public static double circleArea, circlePerimeter;
    public DrawCircle(CustomPanel1 customer){
    super(customer);
    } // end method
    // use shape to draw an oval, rectangle or triangle
    public void paintComponent( Graphics g )
    super.paintComponent( g );
    initializeShapeVariables();
    for(int i = 0; i<originList.size(); i++){
    String XY =(String)originList.get(i);
    int star = XY.indexOf("*");
    int dot = XY.indexOf(".");
    int comma = XY.indexOf(",");
    int shapeToDraw = Integer.parseInt(XY.substring(0,dot));
    int pickedX = Integer.parseInt(XY.substring(dot + 1,comma));
    int pickedY = Integer.parseInt(XY.substring(comma + 1, star));
    int shapeSize = Integer.parseInt(XY.substring(star + 1));
    int x = pickedX-(shapeSize/2);
    int y = pickedY-(shapeSize/2);
    // draw a circle
    if ( shapeToDraw == Circle ) {        
    g.drawOval(x ,y , shapeSize, shapeSize );
    if(shapeWasCreated){
    circleArea = (pi * (((double)(shapeSize)/2) * (((double)shapeSize)/2)));
    area += circleArea;
    circlePerimeter = (pi * (shapeSize));
    perimeter += circlePerimeter;
    CustomPanel1.label.setText("Area " + area + "Perimeter " + perimeter);
    } //end if
    } //end if
    } // end for
    if(shapeWasCreated)
    shapeWasCreated = false;
    } // end if
    private void initializeShapeVariables(){
    area = 0;
    perimeter = 0;
    circleArea = 0;
    circlePerimeter = 0;
    } // end method
    // set shape value and repaint
    public static void draw( int shapeToDraw )
    shape = shapeToDraw;
    //repaint();
    } //end method
    } // end class
    // A customized JPanel class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class DrawSquare extends DrawShape {
    public static double squareArea, squarePerimeter;
    public DrawSquare(CustomPanel1 customer){
    super(customer);
    } // end method
    // use shape to draw an oval, rectangle or triangle
    public void paintComponent( Graphics g )
    super.paintComponent( g );
    initializeShapeVariables();
    for(int i = 0; i<originList.size(); i++){
    String XY =(String)originList.get(i);
    int star = XY.indexOf("*");
    int dot = XY.indexOf(".");
    int comma = XY.indexOf(",");
    int shapeToDraw = Integer.parseInt(XY.substring(0,dot));
    int pickedX = Integer.parseInt(XY.substring(dot + 1,comma));
    int pickedY = Integer.parseInt(XY.substring(comma + 1, star));
    int shapeSize = Integer.parseInt(XY.substring(star + 1));
    int x = pickedX-(shapeSize/2);
    int y = pickedY-(shapeSize/2);
    if ( shapeToDraw == Square ){        
    g.drawRect( x, y, shapeSize, shapeSize );
    if(shapeWasCreated){
    squareArea = ( shapeSize * shapeSize);
    area += squareArea;
    squarePerimeter = (4 * shapeSize);
    perimeter += squarePerimeter;
    CustomPanel1.label.setText("Area " + area + "Perimeter " + perimeter);
    } //end if
    } //end if
    } // end for
    if(shapeWasCreated)
    shapeWasCreated = false;
    } // end if
    private void initializeShapeVariables(){
    area = 0;
    perimeter = 0;
    squareArea = 0;
    squarePerimeter = 0;
    } // end method
    // set shape value and repaint
    public static void draw( int shapeToDraw )
    shape = shapeToDraw;
    //repaint();
    } //end method
    } // end class
    // A customized JPanel class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class DrawTriangle extends DrawShape {
    public static double triangleArea, trianglePerimeter;
    public DrawTriangle(CustomPanel1 customer){
    super(customer);
    } // end method
    // use shape to draw an oval, rectangle or triangle
    public void paintComponent( Graphics g )
    super.paintComponent( g );
    initializeShapeVariables();
    for(int i = 0; i<originList.size(); i++){
    String XY =(String)originList.get(i);
    int star = XY.indexOf("*");
    int dot = XY.indexOf(".");
    int comma = XY.indexOf(",");
    int shapeToDraw = Integer.parseInt(XY.substring(0,dot));
    int pickedX = Integer.parseInt(XY.substring(dot + 1,comma));
    int pickedY = Integer.parseInt(XY.substring(comma + 1, star));
    int shapeSize = Integer.parseInt(XY.substring(star + 1));
    int x1=pickedX-(shapeSize/2);
    int y1=pickedY+(shapeSize/2);
    int x2=pickedX+(shapeSize/2);
    int y2=y1;
    int x3=pickedX;
    int y3=pickedY-((int)(1.73205*shapeSize*0.33333));
    if (shapeToDraw == Triangle)
    g.drawLine(x1, y1, x2, y2);
    g.drawLine(x1, y1, x3, y3);
    g.drawLine(x3, y3, x2, y2);
    if(shapeWasCreated){
    triangleArea = (double)(shapeSize * shapeSize/2);
    area += triangleArea;
    trianglePerimeter = (3 * (shapeSize));
    perimeter += trianglePerimeter;
    CustomPanel1.label.setText("Area " + area + "Perimeter " + perimeter);
    } //end if
    } //end if
    } // end for
    if(shapeWasCreated)
    shapeWasCreated = false;
    } // end if
    private void initializeShapeVariables(){
    area = 0;
    perimeter = 0;
    triangleArea = 0;
    trianglePerimeter = 0;
    } // end method
    // set shape value and repaint
    public static void draw( int shapeToDraw )
    shape = shapeToDraw;
    //repaint();
    } //end method
    } // end class

    The drawing panel cannot draw the figures, what's
    wrong?You can't have written this much code and then suddenly detected it doesn't work at all. You must now restart from the point where you had a working program. Then you add code is small increments and see to it that it works in each step and you understand why it works. This method is called stepwise refinement and it does wonders.

  • 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.

  • Interface Builder and subclassing

    Is it possible for me to have the outlet in Interface Builder pointing to a superclass... then in the code using that interface to point to a subclass?
    So for example, suppose I'm setting up an interface in Interface Builder with a HumanView (let's say this is a subclass of UIView)... suppose this is like a character in an MMORPG... and you're customizing your chaacter...
    and correspondingly in my code I have:
    IBOutlet HumanView *character;
    But I'm uncertain whether this view will be a female or male character... In my code I have two subclass of HumanView... FemaleView and MaleView... each with its own unique instance variables and methods...
    Is it possible for me to decide in the program to have make "character" a FemaleView or MaleView?
    Thanks.
    Message was edited by: iphonemediaman

    Not a problem. I did realize I should add one minor clarification.
    1) You can cast a quadralateral to a square in one instance. When you know that actual object (the structure in memory) is a square.
    So, to be complete, you can safely cast a the square to a quadralateral all day long -- you know that a square is always a quadralateral. But if you are going to cast the quadralateral to a square, you should make sure you actually have a square object. The compiler will let you do it (might show a warning), but you could end up trying to reference pieces of a square that may not actually be part of the actual object. aka (in pseudo code):
    // no issues with these two alloc/inits
    Quad *foo = (Quad *)[[Square alloc] init];
    Quad *bar = (Quad *)[[Rectangle alloc] init];
    // both would return 4
    [foo numSides];
    [bar numSides];
    // if setSideLength is only a method on a Square, then
    // first line works fine
    [(Square*)foo setSideLength:20.0];
    // this line, however, will likely give a compiler warning and then
    // an EXC_BAD* error during runtime -- bar is not actually a square
    // in memory, despite what you are telling the compiler
    [(Square*)bar setSideLength:20.0];
    I hope I didn't conuse the issue -- but wanted to clarify.
    Cheers,
    George

  • Question about generics and subclassing

    Hi all,
    This has been bothering me for some time. It might be just me not understanding the whole thing, but stay with me ;):
    Suppose we have three classes Super, Sub1 and Sub2 where Sub1 extends Super and Sub2 extends Super. Suppose further we have a method in another class that accepts (for example) an AbstractList<Super>, because you wanted your method to operate on both types and decide at runtime which of either Sub1 or Sub2 we passed into the method.
    To demonstrate what I mean, look at the following code
    public class Super {
      public methodSuper() {
    public class Sub1 extends Super {
      public methodSub1() {
        // Do something sub1 specific
    public class Sub2 extends Super {
      public methodSub2() {
         // Do something sub2 specific
    public class Operate {
      public methodOperate(AbstractList<Super> list) {
        for (Super element : list) {
           // Impossible to access methods methodSub1() or methodSub2() here, because list only contains elements of Super!
           // The intention is accessing methods of Sub1 or Sub2, depending on whether this was a Sub1 or Sub2 instance (instanceof, typecasting)
    }The following two methods seem impossible:
    Typecasting, because of type erasure by the compiler
    Using the instanceof operator (should be possible by using <? extends Super>, but this did not seem to work.
    My question now is: How to implement passing a generic type such as AbstractList<Super> while still making the methods of Sub1 and Sub2 available at runtime? Did I understand something incorrectly?

    malcolmmc wrote:
    Well a List<Super> can contain elements of any subclass of super and, having obtained them from the list, you could use instanceof and typecast as usual.I agree with you on this one, I tested it and this simply works.
    Of course it would be better to have a method in Super with appropriate implementations in the subclasses rather than use distinct method signatures, instanceof and casting isn't an elegant solution. Alternatively use a visitor pattern.Not always, suppose the two classes have some similarities, but also some different attributes. Some getters and setters would have different names (the ones having the same name should be in the superclass!). You want to be able to operate on one or the other.
    Generics doesn't make much difference here, exception it would be more flexible to declare
    public methodOperate(AbstractList<? extends Super> list) {Which would alow any of AbstractList<Super>, AbstractList<Sub1> or AbstractList<Sub2> to be passed.I tried it and this also works for me, but I am still very, very confused about why the following compiles, and gives the result below:
    public class Main {
         public static void main( String[] args ) {
              AbstractList<Super> testSub = new ArrayList<Super>();
              testSub.add( new Sub1( "sub1a" ) );
              testSub.add( new Sub1( "sub1b" ) );
              accept( testSub );
         private static void accept( AbstractList<? extends Super> list ) {
              for ( int i = 0; i < list.size(); i++ ) {
                   Super s = list.get( i );
                   System.out.println( s.overrideThis() );
    public class Sub1 extends Super {
         private String sub1;
         public Sub1( String argSub1 ) {
              sub1 = argSub1;
         public String overrideThis() {
              return "overrideThis in Sub1";
         public String getSub1() {
              return sub1;
    public class Sub2 extends Super {
         private String sub2;
         public Sub2( String argSub2 ) {
              sub2 = argSub2;
         public String overrideThis() {
              return "overrideThis in Sub2";
         public String getSub2() {
              return sub2;
    public class Super {
         public Super() {
         public String overrideThis() {
              return "OverrideThis in Super";
    }With this output:
    overrideThis in Sub1
    overrideThis in Sub1Even using a cast to Super in Main:
    Super s = (Super) list.get( i );does not return the Sub1 as a Super (why not??)
    Sorry for the long code snippets. I definitely want to understand why this is the case.
    (Unwise, I thing, to use Super as a class name, too easy to get the case wrong).OK, but I used it just as an example.

  • Object Libraries and Subclassing

    I am trying to use an object library to store standard objects for re-use. Every time I try to use these objects the message 'Frm - 18108 , failed to load objects' appears. The object library is in the same directory as the form. Even if I use a 'Smartclass' the problem still occurs !
    Does a system path have to be set to look for libraries ?
    Do I have to do something else to get the libraries to work ?
    Please help !

    Hi Shaw,
    Let us assume that you have stored your (.fmb) file in the following location:(C:\Working\my_form.fmb). Then all you need to do is, in your 'Registry Editor' under HKEY_LOCAL_MACHINE -> SOFTWARE -> ORACLE folder, select 'FORMS60_PATH' string and append C:\WORKING; with the existing sting value. Then, open Forms Builder (Close if already open), open your required form which contains referenced objects from OLB. Now, your form should open without any problem.
    Let me know if your still face any problem.
    Regards,
    Masilamani D.
    null

  • Overriding and Overloading

    Hi,
    I'm new to abstract Java world.
    If I compare Overide and Overload,
    Does it just mean
    OVERIDE superclass and subclass having same method name with different functions?
    But OVERLOAD is having more than 1 method with the same name but with different functions?
    Thanks,

    Generally you're right. In specification there is "method signature" used to distingush it.
    overide: exactly same signature but different implementation in subclas
    overload: same name but different signature, means: list of arguments, thrown exception

  • Inheritance and synchronized keyword

    Hello all,
    If I declare some methods synchronized in a class, extends it and declare some other methods in the inheriting class as synchronized, will they (superclass and subclass methods) all still synchronize on the same lock/monitor/whatever?
    -teka

    kjhermans example wont even compile!
    Actually :
    synchronized void method() {
      // code
    is equivalent to :
    void method() {
      synchronized(this) {
        // code
    }So yes, all methods synchronize on the same lock : this
    And this is the same even across the class hierarchy.
    This means, that if you have 2 instances, 2 methods may be executed simultanly, each with another instance.
    But never will 2 synchronized methods be called on the same instance, even when the methods are declared at different places in the hierarchy.
    If you want to be shure that 2 methods are never called simultanly, even not when called on different instances, you have to use a static mutex :
    class MySuper {
      static Object mutex = new Object();
      void method() {
        synchronized(MySuper.mutex) {
          // code
    class MySub {
      void method2() {
        synchronized(MySuper.mutex) { // same mutex as in MySuper
          // code
    }

  • Reg. METHOD redefnition

    Hi,
    I tried to inherit a subclass from super class. In se38, i created supercalss and subclasses as local classes. Here in subclass, the system was expecting the keyword REDEFINITION while resuing the same method in the subclass.
    But when i do the same thing in SE24 for creating a Global Class, the system was not asking to redefine the method.
    Can anyone tell me what could the difference?
    Regards,
    Prabu

    Hi Marcin,
    Thanks for your response.
    I still have the same doubt.
    See the following code, i ahve used the only method DISPLAY in both superclass and subclass. Here if i remove the keyword REDEFINITION from the subclass. I am getting the error as " method DISPLAY as already been declared "
    class lc_superclass DEFINITION.
      PUBLIC SECTION.
      METHODS : display.
    ENDCLASS.
    CLASS lc_superclass IMPLEMENTATION.
      METHOD display.
      ENDMETHOD.
    ENDCLASS.
    CLASS lc_subclass DEFINITION INHERITING FROM lc_superclass.
      PUBLIC SECTION.
      METHODS : display REDEFINITION.
    ENDCLASS.
    CLASS lc_subclass IMPLEMENTATION.
      METHOD display.
      ENDMETHOD.
    ENDCLASS.
    Can you please correct if i am wrong.
    Regards,
    Prabu

  • Can't extend my own class (why?)

    I am working my way through a JSP tutorial (Wrox publishing) and cannot compile my program: ChildrenBook.java
    The tutorial has me extend the class Book (which I created and compiled).
    The Book.class file is found in the "com\wrox\library\" directory.
    Book is declared as public
    It used in ChildrenBook as follows:
    package com.wrox.library;
    public class ChildrenBook extends Book
    The file ChildrenBook.java is located in "com\wrox\library\" directory.
    The error I receive from the compiler is:
    cannot resolve symbol
    symbol : class Book
    I imagine I'm doing something wrong that is foolishly simple. Any thoughts are most appreciated.

    I believe I have both classes in the same package. I
    placed them both in the same directory
    com\wrox\library\
    In both the superclass and subclass I start with the
    following code:
    package com.wrox.library;
    I just tried the import statement, as you suggested,
    import com.wrox.library.Book;
    and I get a "cannot resolve symbol" for my reference
    to Book.You don't use "import" if all the classes are in the same package. The compiler and runtime environment will detect the classes.
    >
    As you stated, and this just confirms it, my program
    is not recognizing the existence of my Book.class
    file. I checked the properties of the file to see if
    anything funky is going on with it but there is
    nothing out of the ordinary.While compiling try using using -classpath directive and supply the correct class path.

  • Working with oracle object type tables

    Hi,
    I've created a table which only contains Oracle object types (e.g. CREATE TABLE x OF <...>). When I create an Entity for this table using the Entity wizard, I end up with an entity with the attributes of the base object type and two special attributes REF$ (reference to the object type instance) and SYS_NC_OID$ (unique object identifier). The REF$ attribute is on the Java side of type oracle.jbo.domain.Ref and the other attribute is on the Java side a simple String.
    It seems this only allows me to save objects of the base type in this table. First of all in my situation this is also impossible because the base type is not instantiable. What I do want is to save several different subtypes into this table using the BC4J custom domain mechanism. Is there any way to make this possible? I first thought I could maybe do something with the special REF$ attribute, but this doesn't seem te case. So I might need to override most of the EntityImpl methods, like doUML, remove etc. Am I right? And does anyone have any hints on how to do this?
    Regards,
    Peter

    Peter:
    Hi,
    I've created a table which only contains Oracle
    object types (e.g. CREATE TABLE x OF <...>).
    When I create an Entity for this table using the
    Entity wizard, I end up with an entity with the
    attributes of the base object type and two special
    attributes REF$ (reference to the object type
    instance) and SYS_NC_OID$ (unique object identifier).
    The REF$ attribute is on the Java side of type
    oracle.jbo.domain.Ref and the other attribute is on
    the Java side a simple String.
    It seems this only allows me to save objects of the
    base type in this table. First of all in my situation
    this is also impossible because the base type is not
    instantiable. What I do want is to save several
    different subtypes into this table using the BC4J
    custom domain mechanism. Is there any way to make
    this possible? Sorry, but this is not supported out of the box.
    Since you have an object table, you wouldn't use domains to achieve this. Instead, you would have a superclass and subclass entity objects, e.g., PersonEO subclassed into StudentEO and EmployeeEO.
    I first thought I could maybe do
    something with the special REF$ attribute, but this
    doesn't seem te case. So I might need to override
    most of the EntityImpl methods, like doUML, remove
    etc. Am I right? And does anyone have any hints on
    how to do this?
    If you want, you can try this by overridding EntityImpl's:
       protected StringBuffer buildDMLStatement(int operation,
          AttributeDefImpl[] allAttrs,
          AttributeDefImpl[] retCols,
          AttributeDefImpl[] retKeys,
          boolean batchMode)
    and
       protected int bindDMLStatement(int operation,
          PreparedStatement stmt,
          AttributeDefImpl[] allAttrs,
          AttributeDefImpl[] retCols,
          AttributeDefImpl[] retKeys,
          HashMap retrList,
          boolean batchMode) throws SQLException
    Handle the case when operation == DML_INSERT.
    There, build an insert statement with substitutable row, e.g.:
    INSERT INTO persons VALUES (person_t('Bob', 1234));
    INSERT INTO persons VALUES (employee_t('Joe', 32456, 12, 100000));
    where person_t and employee_t are database types and you are invoking the respective constructor.
    Thanks.
    Sung

  • Extended but NOT polymorphic Entity Object ?

    Hi,
    We are trying to implement the OO features of ADF BC, i.e : Inheritance and Polymorphism, to reuse the logic in EO. I need some confirmation below to make sure we apply it correctly :
    1) We can Extend Entity Object WITHOUT assigning any discriminator, can't we ?
    (this is what I call Extended but NOT polymorphic )
    If the answer is yes , then I have further question :
    2) In our Order Processing module of our ERP application, there are following entity object : SalesOrder, Invoice, SalesReturn, CreditNote
    And there are four underlying database tables : SalesOrder, Invoice, SalesReturn, CreditNote.
    They are surely DIFFERENT transaction BUT they have COMMON attributes (and validation), This is why I call it "Extended but NOT polymorphic".
    The common attributes are :
    - DocID (PK)
    - DocNumber
    - DocDate
    - Warehouse
    - Customer
    - Salesman
    - TermOfPayment
    - DueDate
    So I create one BaseOrderEntity as super class entity. Then I create four entity objects that extend the base entity :
    Entity : SalesOrder, Extend : BaseOrderEntity, Database Object : SalesOrder
    Entity : Invoice, Extend : BaseOrderEntity, Database Object : Invoice
    Entity : SalesReturn, Extend : BaseOrderEntity, Database Object : SalesReturn
    Entity : CreditNote, Extend : BaseOrderEntity, Database Object : CreditNote
    Is this the correct way to apply it ?
    In other word, is this the correct use case ?
    Thank you very much,
    xtanto.

    Starting in JDeveloper 10.1.2, the ADF runtime throws an error if it detects that you have a superclass and subclass entity objects without properly-configured discriminator attributes. If you do not intend to instantiate the superclass, just assign it a descriminator attribute with a value that will never occur in real-life, like NULL or 'x' or whatever.
    It will be simplest if all your family of subclasses were stored in the same table, although that is not required. It simply makes the polymorphic queries easier.
    If you want to avoid the runtime check for the discriminator's being properly configured, because you know that your application will never run the chance of loading the same row into the entity cache as two different entity definition types, then you can get a property jbo.abstract.base.check in your configuration (or as a System property) to the value false and then the check is not performed.

  • Use of jdbc-class-ind-value

    Hi,
    I have 2 questions about jdbc-class-ind-value attribute.
    First it is not clear what are the allowed value types: number, single
    chars, full strings ?
    Second, as stated in chapter 7.8.2 of the manual, application should ensure
    that all
    the classes in a hiearchy are loaded in order to have correct results in
    query.
    Well, the PresistenceManager should be able to do that by itself, I think.
    Once a class is referenced as target of a query, it can be searched in
    metadata
    and/or .mapping or any other MappingFactory, and collected the list of
    values
    for all the subclasses (that are registered in .jdo files available in
    classpath).
    Am I wrong ?
    Regards,
    Guido.

    Guido-
    In article <c9202v$guf$[email protected]>, Guido Anzuoni wrote:
    Hi,
    I have 2 questions about jdbc-class-ind-value attribute.
    First it is not clear what are the allowed value types: number, single
    chars, full strings ?The value can be a number, char, or string ... Kodo will automatically
    determine the type of column to use based on the values you enter.
    Second, as stated in chapter 7.8.2 of the manual, application should ensure
    that all
    the classes in a hiearchy are loaded in order to have correct results in
    query.
    Well, the PresistenceManager should be able to do that by itself, I think.
    Once a class is referenced as target of a query, it can be searched in
    metadata
    and/or .mapping or any other MappingFactory, and collected the list of
    values
    for all the subclasses (that are registered in .jdo files available in
    classpath).
    Am I wrong ?This isn't possible, since Kodo cannot reliably determine all the
    subclasses for a particular class. For example, if you have superclass
    somepackage.SuperClass and subclass someotherpackage.SubClass, Kodo
    would need to scan through every jar and directory everywhere in your
    CLASSPATH in order to try to locate all of the possible persistent
    classes. Furthermore, in a managed environment (or other environment
    that has a custom class loader, such as a network class loader), it
    often isn't possible to perform this sort of scanning at all.
    Regards,
    Guido.--
    Marc Prud'hommeaux
    SolarMetric Inc.

  • Inheritance in bytecode!

    Hi Everyone,
    Am just curious about the way subclasses and superclasses are paired after compilation in byte code. For instance, if we have a superclass called HugeSuperClass and numerous subclasses inheriting its many members, then does the relationship between the superclass and subclass still exist in byte code where the JVM during interpretation goes on fetching bits and pieces from all over the place OR does each class become a kind of independent module ready to be interpreted by the JVM? I guess if the latter would be true then byte code for each class would be Big, considering all the ready Java lib classes and user-defined classes.
    Thanks in advance!

    First of all: The idea of Java is that it's of a high enough level that you usually don't need to take care of such details, just assume that the compiler and the JVM do the right thing until you've got reason to believe the opposite.
    You could simply experiment with that:
    - Create a huge class (lots of member variables, lots of methods, lots of code)
    - create a small derived class that only adds a single method
    Check the size of the class files. I'd bet that the first class file will be considerably larger than the second. You might also want to look into some decompilers (or byte code viewer plugin for Eclipse, if you use it) to get some idea about how your code is translated.

Maybe you are looking for

  • Returning to home screen?

    I leave my iPhone at the home screen and it enters the sleep mode. I get a phone call, up popes on the screen who it is. I answer it and when I hang up it returns to the sleep mode. Works great but when I take it out of the sleep mode the screen is i

  • "Archive" feature not working in Apple Mail - v5.1 (1251/1251.1) - LION 10.7.2

    I am trying Archive feature on my IMAP account using following menu option(pls check screenshot) It always fails to Archive and gives this error The message "Subject" could not be moved to the mailbox "(null)" The destination mailbox does not exist.

  • Access Permissions

    I have a Java program which is embedded on our main intranet page. Recently, I've made some changes to the permissions of the local PC's where users no longer have full local administrator privileges. since this change occurred however, users are una

  • Do I Need COsting Sheet

    Hi all CO Gurus, I have a scenario where for all cost estimated (std cost), the overheads for General and Admin are based on forecast for current year. However, the formula actually has a weight factor acctached to it to split forecast overheads betw

  • Adding an URL to the Favorites

    Hi, We have a web application for which there are 100's of users. Most of them do not know how to add an URL to the Favorites in the IE.Any ideas like creating a batch file and emailing it to them so that it adds the URL to the favorites when they cl