Overriding methods and attributes

can a subclass override a method in its superclass even if it changes the method`s access modifier? can attributes be "overriden" as well?for instance:
//superclass
class A implements Serializable{
public int attr;
public void run () {
//subclass
class B extends class A {
transient int attr;
private void run() {
}will public int attr of class A be "overriden" by transient int attr of class B? and did class B override the run method?
thanks!

while overriding a method, you cannot make the method being overriden more 'private'. That means if a method is public in the parent class, you can not make it package or protected in the child class and so on.
As far as overriding the attributes is concerned, I haven't seen anything like that and I think it's not allowed. The transient int in B is different that the public int in A.
Correct me if I am wrong.
Thanks.

Similar Messages

  • Hiding methods and attributes while inheriting

    Hello All,
    This is kinda urgent. While making a subclass I want to block access to methods and attributes of super class when anone creates an object of sub-class. In my particular situation I cannot override the methods.
    Let me explain it with an example:
    I have a class A which contains an attribute of type Object. All the methods accept Object type parameters and act accordingly. Now I want to create a sub-class B which acts on Strings only. I can create a wrapper to class A but I want to add some behavior which is specific to strings and use rest of the behavior as in class A. I cannot override the methods of class A because they take Objects as parameters whereas in class B the same methods take string as parameters.
    I hope you have understood the problem. Please reply ASAP.
    Thanks in advance

    Sorry the diagram turned out wrong. ObjectClass and StringClass are both supposed to be derived
    from the AbstractBaseClass.
    This method is one way to achieve what you want. You make an AbstractBaseList class that has only
    protected methods that take objects.
    To implement a generic Object version of this class you extend it and override the protected methods in
    the AbstractBaseList class to make them public.
    To implement a String list you extend the AbstractBaseList class and override the protected methods to
    make them public (but change the type of the parameters).
    The only problem with this approach is that the return types of the methods cannot be changed. Therefore
    I recommend the AbstractBaseList implement a method called
    protected Object getByIndex(int i) {
    // do list type stuff in here
    Then the ObjectList can implement
    public Object get(int i) {
    return super.getByIndex(i);
    and the StringList can implement
    public String get(int i) {
    return (String) super.getByIndex(i);
    In effect all you need to do is to implement wrapper classes that enforce type casting on the Object based
    set/get values.
    Another option is to use JDK1.5 with its generics classes. These effectivly allow you to specify which type of
    object an instance of a class accepts.
    Another question. What is the matter with the Collections classes provided in the JDK?
    matfud

  • Overriding Methods and super.method()

    I've got some custom classes that extend and extension of the
    MovieClip. At the end of the movieclip timeline I want the end
    users to be able to simply call myMethod to signal they are at the
    end of the timeline. Certain classes will need to do something
    things and others yet others, but they will all also need to do a
    few things in common.
    I was hoping to define the "in common" things in the super
    class and then overide the method for the extensions. So in my
    example I was hoping that an instance of Class B would do what it
    needed to do and then call the super function. However Class C has
    nothing specific itself to do and since the method wasn't overriden
    the same myMethod() on the timeline would invoke the super classes
    method.
    So the case of Class C works. But in the case of Class B. I
    get the trace that the Class B method has been called, but I don't
    get a message that Class A was called. Is there a way to make this
    idea work? Is it a good idea? What am I missing?

    Okay I've worked it out. The trick comes in with how you call
    myMethod(). On the timeline I have to be sure and use a qualified
    reference. So, this is on the of an instance of B, if I use
    myMethod();
    I only get the myMethod() from class B, but if I do:
    this.myMethod()
    I get B and A. But oddly enough if I say invoke myMethod from
    the constructor of B, I get both trace statements -- regardless of
    whether or not I use a qualified reference! Now that is strange.

  • Do the Interface contains static components like static methods and attribu

    Do the Interface contains static components like static methods and attributes ?

    >
    You have to supply a bit more detail: is that Lotus
    Notes API a Java API?Hmm, It's Java interface to Lotus Notes API
    Does it use JNI? Perhaps it is used somewhere underneath, I do not know for sure, but I think so
    Possibly the Lotus Notes
    implementation keeps a
    reference to those arrays, who knows?
    Maybe, but I'd be really suprised if it did. I derive this thread from Lotus Notes class and provide my own "worker method", overriding Lotus API abstract one, where I reference arrays. Arrays are specific to my program and since they are private fields in thread's class Lotus Notes layer does not have any way of referencing them, nor any reason for this matter
    For starters: if you zero out (set to null) your
    references to those arrays
    in your threads when the threads finish, there might
    surface a useful
    indication that you can blame Lotus Notes for this
    Well, I've become deeply suspect of whether these Notes' threads do really finish :-) My method finishes for sure, but it is just a part of run() method of Lotus Notes thread. Anyway, you can always safely blame Lotus Notes for almost anything :-)

  • Why do we need to override Hascode and Equals method?

    Hi,
    == checks if the two references are equal and .equlas will check if the value is same, if we want .equals to take care of both reference and value are correct. why cant I just override equals with an extra check that references are equal(==).
    Please someone elaborate on this and also tell me what role hashcode plays in this.
    thanks
    Anirudh

    anirudh1983 wrote:
    if we want .equals to take care of both reference and value are correct. why cant I just override equals with an extra check that references are equal(==).Many equals() methods do run an '==' check first for efficiency (and I would recommend it if you're writing one yourself).
    Please someone elaborate on this and also tell me what role hashcode plays in this.The reason that it is good practise to override equals() and hashCode() together is to maintain consistency.
    Hashcodes are used by all Java collections that contain the word 'Hash' in their name, and may also be used by other programs that need a hash code for identification; so if you supply one, you must follow the rules (which you can find in the API for Object.equals() and Object.hashCode()).
    The main rule is this: *objects that are equal() must have equal hashcodes*.
    Note that the reverse is NOT true: objects that are not equal() do not have to have different hashcodes, but it is usually better if they do.
    There is quite a lot to know about hashcodes, and what makes a good one, so I suggest you follow dcminter's advice if you want to be a happy and prosperous Java programmer.
    Winston

  • Extending classes and overriding methods

    If I have a class which extends another, and overrides some methods, if I from a third class casts the extending class as the super class and calls one of the methods which gets overrided, is it the overrided method or the method of the superclass which get executed?
    Stig.

    Explicit cast can't enable the object to invoke super-class's method. Because dynamic binding is decided by the instance. The cast can just prevent you from using methods only defined in sub-class, but it does not let the object to use super-class's method, if the method's been overrided. Otherwise, the polymophism, which is one of the most beautiful feature of Object-Oriented thing, can't be achieved. As far as I know, the only way to use super-class's method is the super keyword in the sub-class, and seems no way for an object to do the same thing (I may wrong, since I haven't read the language spec).
    here's a small test:
    public class Test {
    public static void main(String[] args){
    A a = new B();
    a.method();
    ((A)a).method();
    class A{
    public void method(){
    System.out.println("A's method");
    class B extends A{
    public void method(){
    System.out.println("B's method");
    The output is:
    B's method
    B's method

  • Method, parameters and attributes

    Dear SAP friends!
    Could anybody explain me how to find possible values of a parameter?
    Here is an example:
       CALL METHOD o_picture->set_display_mode
           EXPORTING
             display_mode = cl_gui_picture=>display_fit_center.
    Parameter "display_mode" has 4 possible values. The parameter values could be found in Attributes Tab.
    But how I can identify that these 4 values are related to "display_mode" parameter?
    Let's say I want to use method "set_display_mode" of class "cl_gui_picture".
    I go to SE84 and display the class. Then I find the method I want to use and click "parameters". Then I see the parameter "display_mode".
    I know that possible values of the parameter could be found in Attributes Tab. But there so many of them...
    How do I know which is which?  Clicking on "display_mode" doesn't give any information and there is no documentation available in English... 
    Thanks,
    Tatyana

    Yes, this is a little bit tricky at times.  But the class, method, attributes are designed to be intuitive, meaning that the wording of the methods and and attributes are described in such a way that it is easy to recoginize what contansts can be used to pass to method calls.  Lets take the class CL_GUI_DOCKING_CONTAINER for example.  Lets look at the CONSTRUCTOR method  and its parameter  SIDE.  You will see that this parameter is of TYPE I and that it is actually using on of the constants as its default,  DOCK_AT_LEFT.  So if you go to the attributes tab and look for DOCK_AT_LEFT, you will find other contants that are available to pass to this parameter.
    If you are looking for a hard list of values(or constants in attributes tabs) which can be passed to any given parameter of any given method,  I do not believe that this functionality exists.
    REgards,
    Rich Heilman
    Regards,
    Rich Heilman

  • Override the name attribute in inputText or inputHidden

    Hi all,
    Is it possible to override the name attribute of an input element? For example, the following JSF page:
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <f:view>
    <html>
    <body>
    <h:form>
      <h:inputText/><br />
      <h:inputHidden /><br />
      <h:inputText id="input1" /><br />
      <h:inputHidden id="input2" /><br />
    </h:form>
    </body>
    </html>
    </f:view>Produces the following HTML:
    <html>
    <body>
    <form id="j_id_jsp_188410409_1" name="j_id_jsp_188410409_1" method="post" action="/cbs/test.jsf" enctype="application/x-www-form-urlencoded">
    <input type="hidden" name="j_id_jsp_188410409_1" value="j_id_jsp_188410409_1" />
    <input type="text" name="j_id_jsp_188410409_1:j_id_jsp_188410409_2" />
      <br />
      <input type="hidden" name="j_id_jsp_188410409_1:j_id_jsp_188410409_3" /><br />
      <input id="j_id_jsp_188410409_1:input1" type="text" name="j_id_jsp_188410409_1:input1" /><br />
      <input id="j_id_jsp_188410409_1:input2" type="hidden" name="j_id_jsp_188410409_1:input2" /><br />
    <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="_id2" />
    </form>
    </body>
    </html>Would I have to write a custom component and then override the getName and setName attributes?
    Many Thanks
    Andy

    Note that the HTML you posted does not match the JSF source you posted.
    If you just need dependable names, add an id to the <h:form> and then the name will be in the format formId:inputId.
    Another possibility is to use the prependId attribute of <h:form> to suppress the name mangling.
    Yet another possibility is to use the forceId attribute of the Tomahawk components.

  • Override doDML() and preserve returning key

    Hi OTN,
    Situation:
    I have a composition assotiation between entities Master and Detail with Cascade Update Key Attribute enabled.
    Master's PK is DBSequence type populated by DB trigger.
    MasterVO's and DetailVO's rows are inserted in a single transaction and cascade update key for DetailVO works fine.
    Problem:
    Now I need to override Master's doDML() method to call a DB procedure which performs INSERT with some additional logic.
    After I override doDML cascade update key doesn't work any more for Detai - I get error message as if I would tru to insert a Detail row with NULL as a key.
    I should write some RETURNING code in SQL procedure or smth?..
    Need an advice.
    Thanks.
    JDev 11.1.1.3, ADF BC

    Hi ILya,
    It seems that ur Details Entity is getting updated first before the Master..........
    For check the same just override the details Entity doDML() method and run the App in debug mode....
    Keep breakpoint in both the doDml() methods and check which one is firing first........
    If so then u have forcibly make the master to post the changes first....... follow the below code for achiving the same..........
    <<ur Master Entity Impl Name>> masterImpl = get<<getter of the Mater Entity Impl Exposed in ur Details Entity>>();
    if (masterImpl != null && masterImpl.getPostState() == STATUS_NEW) {
    masterImpl.postChanges(e);
    Regards,
    Suganth.G

  • Oracle.jbo.AttrValException: JBO-27019: Get method for attribute

    Hi Guys,
    I am trying to add a new column to Oracle quoting.It has already been customized by some consultant few years back. I followed the note 392728.1 on metalink and also have the documentation by the previous consultant but getting the error oracle.jbo.AttrValException: JBO-27019: Get method for attribute Draft in HeaderVO could not be resolved after adding my column, when I try to print the quote.
    Here are the steps I took
    1) added a column to the query (at the end) in HeaderVO.xml
    2) added the below code in the HeaderVO.xml
    <ViewAttribute
    Name="DRAFT"
    IsQueriable="false"
    IsPersistent="false"
    Precision="100"
    Type="java.lang.String"
    AliasName="DRAFT"
    ColumnType="VARCHAR2"
    Expression="DRAFT"
    SQLType="VARCHAR" >
    <DesignTime>
    <Attr Name="_DisplaySize" Value="100" />
    </DesignTime>
    </ViewAttribute>
    3). Modify HeaderVORowImpl.java file to add setters and getters for the newly added view attribute. For example,
    a) case 67: //
    setDRAFT((String)obj);
    return;
    b) case 67:
    return getDRAFT();
    c) ublic void setDRAFT(String s)
    setAttributeInternal(67, s);
    public String getDRAFT()
    return (String)getAttributeInternal(67);
    d) protected static final int DRAFT = 67;
    Everything is dont exactly as per the manual but not sure why I am getting this issue. Any help will be appreciated.

    a) case 67: //
    setDraft((String)obj);
    return;
    b) case 67:
    return getDraft();
    c)public void setDraft(String s){
    setAttributeInternal(67, s);
    public String getDraft(){
    return (String)getAttributeInternal(67);
    d) protected static final int DRAFT = 67;
    can u change it as explained above.. setDRAFT should be setDraft.. and getDRAFT should be getDraft..
    and make sure that the index.. number is exactly matching with the attribute order in the VO

  • Override method on an object construted by somebody

         customMenuComponent.addCustomLink(new CustomLinkComponenet("strlink","Storage Inbox",Index.class) {
                   protected BookmarkablePageLink getBookmarkablePageLink() {
                        BookmarkablePageLink bookmarkablePageLink=   new BookmarkablePageLink("link",clazz){
                             protected void onBeforeRender() {
                                  super.onBeforeRender();
                        return bookmarkablePageLink;
              customMenuComponent.addCustomLink(new CustomLinkComponenet("strlink","Storage Inbox",Index.class) {
                   protected BookmarkablePageLink getBookmarkablePageLink() {
                        BookmarkablePageLink bookmarkablePageLink=   super.getBookmarkablePageLink(){
                             protected void onBeforeRender() {
                                  super.onBeforeRender();
                        return bookmarkablePageLink;
              });the second block of code does not compile please explain me why and what is the workaround ? i can override a method on a object when I initialize with new but cannot override if I get the object from super or somebody constructs why ?

    miro_connect wrote:
    in my case is there way to copy object returned from super to object created in sub and override methods ?Perhaps. You need to know about the implementation of the original object.

  • Difference between text data and attributes in master data?

    Hello,
    a charcteristic in BW maintains texts, hierarchies and attributes.
    What exactly is the difference between texts and attributes?
    Attributes describe master data like a customer. The country where the customer resides, the industry etc. describe and classify the customer. Attributes are not just the structure/metadata of the characteristics. They are also the content. The following table should visualize what i mean:
    customer-no. | name
    112          | mcpherson inc.
    113          | donalds inc.
    Texts contain contain the description of a characteristic. Texts define a characteristic. An example is the customers name. It does not describe the customer but defines him/her.
    Is my understanding about these two parts of master data right?
    What else except the customer's name belongs to the texts?
    If I set up a characteristic like the customer in SAP BW, do I have to create an attribute "name". The name belongs to texts, not to attributes?? If I upload master data then, how does it work?
    Thanks in advance.

    Hi,
    If your analysis includes country and region then country  and region should be included in the Infocube.This is required because only if you include these characteristics then you can restrict your queries for country and region.You may need to select some particular countires/region and show the report.Then you have to restrict your queries to only those countries/region.This is possible only if you have these  characteristic in your infocube.
    I am just envisaging your model like this.
    Characteristic in the Infocube
    Customer
    Country
    Region
    Customer Attributes
    Customer Number (SID which is self generated)
    Customer Address1,2 ,3
    Registration No
    Date of Registration
    Deposit Amount
    etc ...
    Region Attributes
    Region Number (SID)
    Total Customers
    Sale Office Address
    Number of Sales Persons
    Customer Attributes
    Customer Number (SID)
    Total Customers
    Head Office Address
    Number of Sales Persons
    GDP
    Total Population
    So the conclusion is whichever entity you want to restrict or analyse should be a part of Infocube.It is very difficult to do analysis based on attributes as I mentioned in my earlier post that they are only "Display attributes" (u can just show that's it).
    Yes!! there are  methods available for analysis based on characteristics in attributes table and you have to do either with virtual characteristic or replacement path or with writing code in customer exits.But a good design and earlier study of all possible report combination and having a good design will avoid good amount of development time and changes.
    I have suffered  when I had only 0CALDAY in my cube and when I want to take a monthly analysis, I was unable to do it and then I have to redesign my whole cube.
    Please anyone, correct me if I am wrong.
    Regs
    Gopi.

  • Some generic anonymous class overriding methods compile, while others don't

    I have the following (stripped-down) code. The abstract class SessionHandler<T> is used by other code to define and run an operation that needs a session to something. This is best done in my code with anonymous classes, because of the shear number of operations defined. In the EntityOps<T> class, these work great. But, in the last class shown here, SomeClass, the anonymous class definition fails, though the semantics are almost identical. (List<T> vs.List<AnotherClass>) What am I doing wrong here? Or is this a bug in Java?
    Thanks, Tom
    public interface IEntityOps<T> {
        T get();
        List<t> getAll();
    public abstract class SessionHandler<T> {
        abstract T handle(Session session) throws Throwable;
        public final T perform() {
            ... calls handle(session) ...
    // These anonymous class definitions compile fine!
    public class EntityOps<T> implements IEntityOps<T> {
        public T get() {
            T ret = null;
            ret = new SessionHandler<T>() {
                T handle(Session s) throws Throwable {
                    T ret = (some T object calculation);
                    return ret;
            }.perform();
            return ret;
        public List<T> getAll() {
            T ret = null;
            return new SessionHandler<List<T>>() {
                List<T> handle(Session s) throws Throwable {
                    List<T> ret = (some List<T> calculation);
                    return ret;
            }.perform();
    // This anonymous class definition fails with the error:
    // "SomeClass.java": <anonymous someMethod> is not abstract and does not override abstract method handle()
    //     in SessionHandler at line XX, column XX
    public class SomeClass {
        public List<AnotherClass> someMethod() throws {
            List<AnotherClass> ret = null;
            ret = new SessionHandler<List<AnotherClass>>() {
                List<AnotherClass> handle(Session s) throws Throwable {
                    List<AnotherClass> ret = (some List<AnotherClass> calculation);
                    return ret;
            }.perform();
            return ret;
    }

    I added @Override above the abstract method override, and it provides this additional error:
    "HousingConfigImpl.java": method does not override a method from its superclass at line 382, column 17
    I have also reconstructed the code layout in a separate set of classes that have no dependancies, but there's no error coming from these!
    public class CustomThing {
    public interface ISomeInterface<T> {
        List<T> interfaceMethod();
    public abstract class SomeAbstractClass<T> {
        private Class _c = null;
        public SomeAbstractClass(Class c) {
            _c = c;
        protected Class getC() {
            return _c;
        public abstract T methodToOverride(Object neededObject) throws Throwable;
        public final T finalMethod() {
            try {
                return methodToOverride(new Object());
            } catch(Throwable e) {
                throw new RuntimeException(e);
    import java.util.List;
    import java.util.Collections;
    public class SomeInterfaceImpl<T> implements ISomeInterface<T> {
        public List<T> interfaceMethod() {
            return new SomeAbstractClass<List<T>>(CustomThing.class) {
                public List<T> methodToOverride(Object neededObject) throws Throwable {
                    return Collections.emptyList();
            }.finalMethod();
    import java.util.Collections;
    import java.util.List;
    public class SomeOtherClass {
        public List<CustomThing> someMethod() {
            return new SomeAbstractClass<List<CustomThing>>(CustomThing.class) {
                public List<CustomThing> methodToOverride(Object neededObject) throws Throwable {
                    return Collections.emptyList();
            }.finalMethod();
    }So, there's something about my code that causes it to be, somehow, different enough from the example provided above so that I get the error. The only differences in the override method definitions in my actual code are in the return type, but those are different in the example above as well. Here are the class declarations, anonymous abstract class creation statements, and abstract method declarations from the actual code.
    public abstract class SessionHandler<T> {
        abstract T handle(Session session) throws Throwable;
    public class EntityOps<T> implements IEntityOps<T> {
                return new SessionHandler<List<T>>(_mgr, _c, "getAll" + _c.getName()) {
                    List<T> handle(Session s) throws Throwable {
    public class HousingConfigImpl implements IHousingConfigOperations, ISessionFactoryManager {
                ret = new SessionHandler<List<Tenant>>((ISessionFactoryManager)this, Housing.class, "getTenantsInNeighborhood") {
                    List<Housing> handle(Session s) throws Throwable {I can't for the life of me see any syntactical difference between my example and the real code. But, one works and the other doesn't.

  • Check Required Elements and Attributes in JAXB

    Hi
    I need check required elements and attributes in JAXB java classes , if there are any value for them place it , otherwise place default value in xml file , because of it I upgrade JAXB2.0 to JAXB 2.1 to support "required" in "XmlElement" , I read in "JavaWS(JAXB)Tutorial.pdf" that JAXB itself check required elements and attributes , if there are any value for them place it , otherwise place default value in xml file , the exact part of document is :
    << A property is said to have a set value if that value was assigned to it during unmarshalling or by invoking its mutation method. The value of a property is
    its set value, if defined; otherwise, it is the property’s schema specified default value, if any; otherwise, it is the default initial value for the property’s base type as it would be assigned for an uninitialized field within a Java class. >>
    I want to know , dose JAXB do this task ? (now I work with JAXB2.1 but it doesnt do this task.Maybe I must set some configuration)
    and if JAXB doesnt do it , how I can check required elements and attributes in JAXB ?
    Please help me.
    Shariat

    its all on Apple's Developer site
    http://developer.apple.com/DOCUMENTATION/AppleApplications/Reference/FinalCutPro _XML/index.html

  • Open hub destination of text and attribute for Functional Area

    Hi Expert
    I have a requirement to accommodate both attribute ( 0FUNCT_LOC_ATTR)  and text ( 0FUNCT_LOC_TEXT ) for functional area in open hub destination .For this a DSO has been created from both 0FUNCT_LOC_ATTR, 0FUNCT_LOC_TEXT data sources .Problem is that DSO has 0FUNCT_AREA ( Functional Area ) as only key fields . So text for both english ( EN ) and Dutch ( NL) for particular 0FUNCT_AREA not getting loaded .If we assign both 0LANGU and 0FUNCT_AREA as composite key of dso , data from attribute transformation is loaded as blank as there is no language filed in attribute data source ( 0FUNCT_LOC_ATTR ).   Please let me know how can I design to accommodate both text for different language and functional area for open hub destination  .
    I know that I can create separate open hub destination for master data TEXT and Attribute.
    Any help is highly appreciated.
    Regards
    Saikat

    HI Saikat,
    You can create an additional characteristics counter and make it a key field in the DSO.After that we can populate this characteristics in the end routine .It value would increase by 1 everytime  different text comes for the same functional area.
    Sample code
    data: counter type n,
             w_farea type /bio/oifunc_area.
    Sort result_package by func_area.
    count =0.
    *checking whether we have the same functional area or we have a different functional area.
    Loop at result_package assigning <Result_fields>.
    if w_farea is initial or w_farea = <result_fields>-func_area.
    count = count +1.
    else
    count =1.
    endif.
    w_farea= <result_fields>-func_area.
    <Result_fields>-zcount = count.
    ENDLOOP.
    Clear w_farea.
    This way the value of counter would get increased by one everytime a new text comes for the same functional area.We can have any number of texts for the same functional area by this method.
    The only issue would be when some delta update comes for the existing text in this method.If you are doing a full load to the DSO from the datasource, then there would be no issue with this method.

Maybe you are looking for