To access a method frm a class derived frm a base class with the same name

Here' s an example:-
class TestA {
public void start() {
System.out.println("TestA");
class TestB extends TestA {
public void start() {
System.out.println("TestB");
}In main method I do this:-
TestA testA = new TestA();
TestB testB = new TestB();
((TestA)testB).start();Output :-
TestB.
Now when i define the method as static :-
class TestA {
public static void start() {
System.out.println("TestA");
class TestB extends TestA {
public static void start() {
System.out.println("TestB");
}Then output is :-
TestA.
Can anyone let me know that when i say ((TestA)testB).start(); i.e i am type casting TestB obect to it base call then TestA should be printed but it doesn't print but when i declare method as static is does print TestA.
Thanks,
Heena

>
>
Secondly, when i say ((TestA).testB).start(); output is TestB. But when i define start() method as static output is TestA. I need clarity for the same.In the static case, all that the compiler is interested in is the class of the expression before the ".". Because you've put in an explicit cast the type of expression is assumed to be TestA the compiler doesn't know what kind of object will actually be referenced at runtime. In the static case which method is called is determined at compile time.
In the instance method case what determines the method called is determined the class of the actual, run time, value of the expression, and despite your cast, the actual value is still a reference to a TestB instance, so the TestB method is called. In the instance case which method called is determined at run time.

Similar Messages

  • How do I call methods with the same name from different classes

    I have a user class which needs to make calls to methods with the same name but to ojects of a different type.
    My User class will create an object of type MyDAO or of type RemoteDAO.
    The RemoteDAO class is simply a wrapper class around a MyDAO object type to allow a MyDAO object to be accessed remotely. Note the interface MyInterface which MyDAO must implement cannot throw RemoteExceptions.
    Problem is I have ended up with 2 identical User classes which only differ in the type of object they make calls to, method names and functionality are identical.
    Is there any way I can get around this problem?
    Thanks ... J
    My classes are defined as followes
    interface MyInterface{
         //Does not and CANNOT declare to throw any exceptions
        public String sayHello();
    class MyDAO implements MyInterface{
       public String sayHello(){
              return ("Hello from DAO");
    interface RemoteDAO extends java.rmi.Remote{
         public String sayHello() throws java.rmi.RemoteException;
    class RemoteDAOImpl extends UnicastRemoteObject implements RemoteDAO{
         MyDAO dao = new MyDAO();
        public String sayHello() throws java.rmi.RemoteException{
              return dao.sayHello();
    class User{
       //MyDAO dao = new MyDAO();
       //OR
       RemoteDAO dao = new RemoteDAO();
       public void callDAO(){
              try{
              System.out.println( dao.sayHello() );
              catch( Exception e ){
    }

    >
    That's only a good idea if the semantics of sayHello
    as defined in MyInterface suggest that a
    RemoteException could occur. If not, then you're
    designing the interface to suit the way the
    implementing classes will be written, which smells.
    :-)But in practice you can't make a call which can be handled either remotely or locally without, at some point, dealing with the RemoteException.
    Therefore either RemoteException must be part of the interface or (an this is probably more satisfactory) you don't use the remote interface directly, but MyInterface is implemented by a wrapper class which deals with the exception.

  • Applet with 2 methods with the same name in ie

    Hi,
    I have a problem with the Java 1.5 plugin for Internet Explorer .
    When my Applet contains 2 methods with the same name but not the same return type, ie does not take the good return type.
    Here is an exemple :
    * Class TestApplet
    package test.applet;
    import java.applet.Applet;
    public class TestApplet extends Applet {
         public void init() {
              System.out.println("init()");
         public void start() {
              System.out.println("start()");
         public String test(String s) {
              System.out.println("test(String) :" + s);
              return s;
         public boolean test(int i) {
              System.out.println("test(int) :" + i);
              return true;
    }I have 2 methods test(), one returns a String and the other a boolean.
    I use the following html code :
    <html>
    <head>
    <script>
    function test() {
         alert(document.DataAccess.test("hello"));
    </script>
    </head>
    <body>
    <applet WIDTH="500" HEIGHT="200" ID="DataAccess" NAME="DataAccess" CODE="test.applet.TestApplet">
    </applet>
    <div onclick="test()">test</div>
    </body>
    </html>
    When I click on "test", the alert show "true" instead of "hello".
    The problem only occurs with a JVM 1.5. It work fine with JVM 1.4.
    Any idea ? Is it a bug ?
    Thanks.

    In your javascript method:
    function test() {
    alert(new String(document.DataAccess.test("hello")));
    MSJVM and SUN jre use different conversion from javaScript objects to Java.
    if you call from javaScript:
    document.getElementById("myApplet").myMethod(22);
    The method in MSJVM should look like this:
    public whatever myMethod(Double d);
    and SUN jre:
    public whatever myMethod(Integer i);
    The best thing to do is this:
    public whatever myMethod(Object o);
                   int col = 0;
                   if (o.getClass().getName().toLowerCase().indexOf("integer") != -1) {
                        col = ((Integer) o).intValue();
                   } else {
                        col = ((Double) o).intValue();
                   }

  • Reflection Classes with the same name

    Hi!
    I have a big problem with reflection. I want to reflect lots of stuff (methods, variables...) in a lot of classes with the same name immediately one after the other. It's like
    copy the file for the analysis to the right place
    do reflection and get results
    copy next file for analysis
    Important to note is, that all of the files that should be reflected have the same name.
    When I run the programm, he always only reflects the first file I gave for analysis, although I know the copying-stuff works and the new file would be there for analysis (but he does not seem to load/use it).
    Any ideas what i could do?
    Thanks!
    ET

    I'm not sure if i'm authorised to tell too much
    details, but i have to do some automated software
    analysis and therefore I need to know whats inside of
    a class and string search would not be appropriate.Why not ? What aspects of the class are you trying to examine ?
    They have the same name, because they are delivered in
    that form from a third party and it would be too much
    effort (and to much risk of errors) to rename them.Sure, if they're delivered as class files, you're unable to rename them. Without knowing more I can't advise you further.
    Why are you interested that much in that topic? Do you
    have to perform a similar task?No, I'm trying to determine if reflection is the right tool for the job. Frankly it doesn't sound like it is. But since you're not authorised to tell me more, I can't help you more.
    Dave.

  • BUG: LabVIEW 8.6 crashes when you save a class vi with the same name

    I am running into an annoying crash.  If you try to add a VI with the same name to an existing class, LabVIEW will notify you that you made an error.  Once you hit OK, LabVIEW crashes.  Obviously, the workaround is not to save any VI with the same name as an existing VI to your class.

    I have attached a ZIP file with an example project.  Open the project and open one of the VIs in Test Class.  Choose File->Save As.  Choose Copy->Open additional copy.  Make sure the box for Add copy to Test Class.lvclass is checked.
    Do NOT try to save the VI over top of the existing VI.   Go to a new folder and save the VI without changing the name.  LabVIEW will save the VI, then inidcate it cannot add the file due to a naming conflict.  Once you hit OK, LabVIEW may or may not hang for a few seconds, then crash.
    When LabVIEW restarts, it does not indicate anything happened. It just comes up with the standard startup screen.
    I stumbled across this attempting to create a copy of an existing VI, but forgetting to change the name.
    I confirmed this does not happen in LabVIEW 8.5.1, so the behavior is new to 8.6.
    Message Edited by Matthew Kelton on 12-19-2008 07:52 AM
    Attachments:
    Class Test.zip ‏19 KB

  • How to access structure in VBScript both Structure and it's only member has the same name

    Hello,
    I VB Script how to access the structure's member if both the structure and the only member has the same name,
    Example,
    Structure name is User and it has only one member called "User" with the Datatype of String.
    When I call using User.User = "Some Text", it is giving me error so I couldn't assign any value to it.
    Kindly help me.
    Nallasivan

    I am using VB Script to Access SAP web Services, the sap web service has a method called user change, there are 3 mandatory parameters username, password and passwordX.
    Here username is string so I can assign value without any problem, password is a type of Bapipwd. Bapipwd is a structure and it has a member called Bapipwd. To access that from VB script I have to use
    Bapipwd.Bapipwd = "Password".
    But when I try to put the statement Bapipwd.Bapipwd = "password" it shows an error message that "Bapipwd doesnt have member called Bapipwd".
    The passwordX also a structure in SAP with the name of Bapipwdx and it has a member "Bapipwd"
    If I user Bapipwdx.Bapipwd="X" it is working fine. Because both the structure and it's member name is different. But Bapipwd.Bapipwd is not working and it gives "Bapipwd doestn't have member Bapipwd"
    I suspect this is due to both the structure and its member has the same name. Kindly help me to access the structure.

  • Can I use multiple p class="logos" tag with the same name within the same html page?

    I was told not to use <div class> tags too many times. I was using them for text, images, to clear floats, I basically built my website using multiple <div class> tags. So if I can't use multiple <div class> tags could I use <p class> tags multiple times in the same html page?
    I have a string of logos at the bottom of my webpage which will all be using the same css characteristics for all logos. Would this be the proper way to write the code:
    HTML
    <p class="logos">Logo1<a href="...></a></p>
    <p class="logos">Logo2<a href="...></a></p>
    <p class="logos">Logo3<a href="...></a></p>
    <p class="logos">Logo4<a href="...></a></p>
    <p class="logos">Logo5<a href="...></a></p>
    <p class="logos">Logo6<a href="...></a></p>
    CSS
    .logos {
    margin-left:10px;
    Here's my website: http://www.darbymanufacturing.com/test_website/index.html - this is the website built with all div class tags
    I restarted the website in order to write the code properly so that I don't come to errors when uploading on the server like I am having with the website link above.

    Instead of writing something like this -
    <p class="logos">Logo1<a href="...></a></p>
    <p class="logos">Logo2<a href="...></a></p>
    <p class="logos">Logo3<a href="...></a></p>
    <p class="logos">Logo4<a href="...></a></p>
    <p class="logos">Logo5<a href="...></a></p>
    <p class="logos">Logo6<a href="...></a></p>
    Why not have something like this -
    <div id="logodiv">
    <p>Logo1<a href="...></a></p>
    <p>Logo2<a href="...></a></p>
    <p>Logo3<a href="...></a></p>
    <p>Logo4<a href="...></a></p>
    <p>Logo5<a href="...></a></p>
    <p>Logo6<a href="...></a></p>
    </div>
    with CSS like this -
    #logodiv p { ... }

  • MSSQLServer4 - Accessing columns from a select with the same name

    The following describes a problem I'm encountering using the MSSQLServer4 driver...I have the following 2 tables (greatly simplified):
    Create Table BOOK( BookId int, Name varchar(50), AuthorId int )
    Create Table AUTHOR( AuthorId int, Name varchar(30) )
    and my select is
    Select BOOK.*, AUTHOR.*
    From BOOK Inner Join AUTHOR On BOOK.AUTHORID = AUTHOR.AUTHORID
    As you can see, the ResultSet from this select will have 2 identically named columns called "Name". I realize I could use an alias to differentiate the column names, but then I must list out every column in each table (quite ugly). I had EXPECTED to be able to do a resultSet.getString( "Author.Name" ), but that doesn't appear to work either. Next, I thought I could use the ResultSetMetaData.getTable()/ResultSetMetaData.getColumnName() to determine the ordinal value, but getTable() always returns "". Is there anyway to distinguish these two columns without using an alias?
    Any help is greatly appreciated.
    Regards...Marc

    Marc wrote:
    The following describes a problem I'm encountering using the MSSQLServer4 driver...I have the following 2 tables (greatly simplified):
    Create Table BOOK( BookId int, Name varchar(50), AuthorId int )
    Create Table AUTHOR( AuthorId int, Name varchar(30) )
    and my select is
    Select BOOK.*, AUTHOR.*
    From BOOK Inner Join AUTHOR On BOOK.AUTHORID = AUTHOR.AUTHORID
    As you can see, the ResultSet from this select will have 2 identically named columns called "Name". I realize I could use an alias to differentiate the column names, but then I must list out every column in each table (quite ugly). I had EXPECTED to be able to do a resultSet.getString( "Author.Name" ), but that doesn't appear to work either. Next, I thought I could use the ResultSetMetaData.getTable()/ResultSetMetaData.getColumnName() to determine the ordinal value, but getTable() always returns "". Is there anyway to distinguish these two columns without using an alias?
    Any help is greatly appreciated.
    Regards...MarcHi. getTableName() will never work because the DBMS doesn't send the necessary metadata with the result
    set that the driver would need to implement that call. If you get 'Name' for multiple column names, JDBC specifies
    that getXXX("Name") will always return the first such named column. The only non-alias way is to know
    the columns you're going to get in order, and just do getXXX(1), getXXX(2) etc.
    Joe

  • I have two user accounts with the same name, but cannot access the old one anymore - all my purchases are on that account! How do I merge the accounts, or recover that particular one?

    I recently encountered a problem with both my account, for some reason it wouldn't accept my new password. And this was about the fith time I'd had to change it! I even wrote it down to ensure I wasn't mistyping it. But for some reaon it wasn't letting me log in form my phone or from my ipad. So I tried to reset it once again. However when I visited the website and searched for my username, it came back saying my 'account name doesn't exist!' I tried again and again but nothing. I thought maybe it would fix itself if I created a new account with the same details, so I did. But now none of my past purchases or my wishlist are showing up - and all my details are exactly the same! I've tried logging in using the old passwrd for my 'other' account but it's not working. And I tried searching for it again to reset the passwrod but it only resets this NEW account.
    I tried sending a request for help, but I need someone with more authority to talk to.
    Please help!

    Antaeus00 wrote:
    I tried sending a request for help,
    But did you succeeed in sending a request for help?
    Did you receive a response? How long has it been since you sent a request?
    but I need someone with more authority to talk to.
    There is no one with more authority than iTunes store support. We herem are only users.

  • JSR 172: error while invoking methods with the same signature

    Hi
    I am facing a peculiar problem which is not making sense to me. This is what I have done:
    1. Written a simple web service that has two methods: sayHello and sayHellToMe. Both these methods have same signatures. They do not take in any parameter and return a string.
    2. Deployed this web service (document/literal) type on Axis 1.2
    3. Generated the stub classes from the wsdl file using Sun Wireless Toolkit's Stub Generator
    4. I have now written a MIDlet that uses this stub class to invoke both the methods one after the other.
    I enabled SOAPMonitor on Axis and saw the SOAP Request and SOAP Response messages. I observed the following:
    1. In the first method: sayHello - everything works fine (with a few tweaks in the Stub class)
    2. However, while invoking the second method sayHelloToMe, the SOAP Body tag in the SOAP Request does not contain any method name. I checked out the Stub class, the qnames and the types are all correct..
    I also realized that this behavior is seen only when I have methods with the same signature in the web service. Any idea why this might be happening? It seems like a very weird problem.
    Any help in this regard will be greatly appreciated.
    Thanks,
    Arati

    Hi, I'm closing this thread and opening the same in another as the content got pasted in reader un friendly format and i'm unable to change the format.
    Thanks,
    Ravi.

  • Initialize/set a base class from a another base class instance

    Hi,
    How can I initialize/set a base class from a another base class instance? I do not want to do a copy of it.
    It would look something like:
    class A {...}
    class B extends A
        B(A a)
            // super = a;
        setA(A a)
            // super = a;
    }Thank you.

    erikku wrote:
    Thanks Winton. It is what I did first but A has lots of methods and if methods are later added to A, I will have to edit B again. For those two reasons, I wanted to use inheritance. The part I was not sure with was the way to initialize B's base (A).You pays your money and you takes your choice. One way (this way) you have to provide forwarders; the other way (inheritance) you have to provide constructors (and if A has a lot of em, you may be writing quite a few).
    Ask yourself this question: is every B also an A? No exceptions. Ever.
    If the answer is 'yes', then inheritance is probably the best way to go.
    However, if there is even the remotest chance that an instance of B should not exhibit 100% of the behaviour of A, now or in the future, then the wrapper style is probably what you want.
    Another great advantage of the wrapper style is that methods can be added to A without affecting the API for B (unless you want to).
    Winston
    PS: If your Class A has a constructor or constructors that take a pile of parameters, you might also want to look at the Builder pattern. However, that's not really what we're talking about here, and it should probably be implemented on A anyway.

  • I have multiple devices with the same cerificate, once I have a an exception for one, FF denys access to the others. I cannot change the certificates, I need to stop FF blocking them.

    I have multiple devices with the same cerificate, once I have an exception for one, FF denys access to the others. I cannot change the certificates, I need to stop FF blocking them.
    == This happened ==
    Every time Firefox opened
    == I attempt to access a web front end on an IBM SVC device

    You can't use the same certificate more than once.
    See also [[Certificate contains the same serial number as another certificate]]

  • No more access to my purchase of Adobe Creative Suite 5.5, my account was no longer activated. I had to crete a new one with the same e-mail address. How can I get my purchase back in my

    Sorry for my poor english vocabulary. I'll do my best to explain.
    I just cleared my computer (Macbook Pro 2011) and wanted to reinstall the Adobe Creative Suite 5.5 Design Standard Student ans Teacher Edition (Mac, English) that I bought (near october, november 2011) but my adobe account was no longer activated. Now that I reactivated it, with the same e-mail, this purchase is no longer in this account. So I was wondering:. How can I get my access back to the downloadable products that I bought?

    I tried to find help with the support by web chat for 2 days already, but every time it says that chat is un available (even if it's suppose to be 24/7)... I dont know what else to do.... please help!

  • How to load the same classes of the same name, from different jars

    Hi,
    I have several different versions of my project in respective jars. I am trying to develop a configuration app, which will have the most current version of my app packaged within it. Then the user will make a selection, and if that selection is an older version, a specific class from one of the jars...which will continue to load other classes within that same jar. If it is the current version, the class will be found within the codebase.
    My question is if this is even possible? Can I load a class from a jar file which has the same file name and package as what is in my current code?

    nasch_,
    So I have been searchin around, and found some good tutorials on classloaders, But i still see a problem.
    Whether I use the same classloader for different sources or not, the problem lies within the reference to the class i am loading. Since this class (a different version of it), is also in the classpath, how does the code know which class is being returned?
    I am having trouble putting this into words, but basically. i don't see how my application will know that i am returning an instance of a class which is not in my classpath.

  • Need to know of a method / process that can be used to send the same msg to all those appearing in my email listings with the same extension after the "@" sign in their address(es) on my macbook [e.g., with "@gov.ca"; Snow Leopard].

    Need to know of a method / process that can be used to send the same msg to all those appearing in my email listings with the same extension after the "@" sign in their address(es) on my macbook [Snow Leopard].

    If you simply want to send the exact same message to everyone in your address book with emails ending in "@whatever.com", you can do the following:
    Create an email with subject, message and attachments but no addresses
    Open Address Book, All Contacts
    Search in Address Book for @whatever.com
    Select the results and drag them into the To: or Bcc: field of the email. If Bcc: then put your email address in the To: field.
    Send the email
    This will not personalize the emails (such as with "Dear firstname:" at the top of the message) but it will let you send an idential message to everyone who meets your criteria.

Maybe you are looking for

  • Credit Management not working for Third Party Sale

    Hi Experts, We have a scenario of Third party sale where sales order generate purchase requision after saving. Now we have appled static credit check to the customer, at the time of saving sales document it warns credit limit is over same time it doe

  • Why is my text messaging app is not working at all, is a blank screen? Help!!!

    My text messaging app is not working at all is a blank screen when I open it! Help!!!

  • Best way to implement selectOneRadio component with "other" option

    I have a selectOneRadio component that has an other option (see below). If the other option is selected I need to pull the value out of a text field. Any ideas on the best way (or any way) to implement this? This is how it looks on the screen... Plea

  • WLAN for a Warehouse

    Hi, We are taking over a new warehouse in the next few months. The business has a requirement for total Wireless Coverage on the Warehouse shop floor for use by stock pickers (with mobile devices). The key challenge I see here is the fact that the ra

  • Including .vbs in JSP

    Hi all Can anyone tel me now to include a .vbs(vb script file) in the JSP i tried like this <script language="vbscript" src="/essPortal/resources/vbs/emulator.vbs"></script> but im getting an script error telling "Type mismatch". But when i place the