Defining a veriable within if statements

hi everyone,
I have a question:
if (true)
   int a = 0;
else if (true)
   String a = "hi";
else
    char a = 'u';
System.out.print(a);How come this doesn't work? It gives me 'undefined variable a' error. Is there another way to do what I am trying to do?
Any comments/suggestions/solutions?

OK guys...I seem to have another problem. What I am trying to do is not as simple as I described above.
I have three user-defined objects (classes). All three classes have some methods with same names that are defined inside the each class. Also they function identically.
To better explain this let me give you an example:
Let say there are three classes: Kid, Teen, Adult
They all have these methods: getName(), getAge(), setName(), setAge()
So code works as following:
loop through all the contents stored in a vector (vector contains some Kids, Teens and Adults)
Object a;
if (true) {
     a = new Kid();.
     a.setName(something);
     a.setAge(something);
else if (true) {
     a = new Teen();
     a.setName(something);
     a.setAge(something);
else {
     a = new Adult();
     a.setName(something);
     a.setAge(something);
String name = a.getName();
int age = a.getAge();
System.out.print(name + age);This doesn't work since those methods are not defined in class java.lang.Object.
Here what I am trying to avoid is following:
Object a;
if (true) {
     a = new Kid();
     a.setName(something);
     a.setAge(something);
String name = a.getName();
int age = a.getAge();
else if (true) {
     a = new Teen();
     a.setName(something);
     a.setAge(something);
String name = a.getName();
int age = a.getAge();
else {
     a = new Adult();
     a.setName(something);
     a.setAge(something);
String name = a.getName();
int age = a.getAge();
System.out.print(name + age);So is there any way to do this without being repetitive.

Similar Messages

  • How to set client within SQL statement without using another pl/sql stmt.

    I have a following select statement
    SELECT SUM (w.prior_forecasted_costs + w.prior_committed_costs)
    FROM xxsuf.job_cost_summary_table w,
    apps.pa_periods p,
    pa.pa_resources bz,
    pa.pa_resource_list_members cz,
    pa.pa_tasks dz
    WHERE w.project_id = z.project_id
    AND w.task_id = dz.task_id
    AND dz.task_number '98000'
    AND w.resource_list_member_id = cz.resource_list_member_id
    AND cz.resource_id = bz.resource_id
    AND NOT EXISTS (SELECT NULL
    FROM pa.pa_tasks zz
    WHERE zz.parent_task_id = dz.task_id)
    AND w.resource_list_member_id != 1000
    AND p.period_name = w.pa_period
    AND p.current_pa_period_flag = 'Y'
    Above select statement uses pa_periods view which only works when I set my client using "exec DBMS_Application_Info.set_client_info(83);" in Toad or SQL*Plus session.
    I was wondering how can I achieve it within select statement. so that I don't have to use another PL/SQL statement to set my client. Is there anyway to set client with my org id within above select statement ?
    Please advise.
    --Rakesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You can simply create a function which calls dbms_application_info and use that in your sql statement as in
    SQL> create or replace function set_client_info (i_info varchar2)
       return varchar2
    as
    begin
       dbms_application_info.set_client_info (i_info);
       return i_info;
    end set_client_info;
    Function created.
    SQL> create or replace view v_emp
    as
      select * from emp where empno = to_number(sys_context('userenv','client_info'))
    View created.
    SQL> select ename from v_emp where set_client_info(7788) is not null
    ENAME    
    SCOTT    
    1 row selected.
    SQL> select ename from v_emp where set_client_info(7900) is not null
    ENAME    
    JAMES    
    1 row selected.

  • ITunes opens and within seconds states it has to close. I've uninstalled

    iTunes will open, but within seconds states it 'Has to close'. Occasionally, I'll see a notice for an update and quickly click to 'Download update?', but when I click on 'Download', a new page opens with 'Thanx for updating', except it hasn't downloaded the update. I have also uninstalled and reinstalled iTunes several times, but that hasn't helped. My phone is a 5S and it won't sync to iTunes either.
    I appreciate any suggestions. Thanx.

    Try working through TS1717: iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues to start with.
    Otherwise, for general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    tt2

  • Can we define a parameter within a subroutine?

    Can we define a parameter within a subroutine?

    Hi,
    see first of all u cannt declare parameters in subroutine if u want u can declare variables locally that is by using the keyword DATA but u cant declare PARAMETERS locally ..
    if it is helpfull plzz reward..
    plzz dont forget to reward.....

  • Can we define a constant within a subroutine

    Can we define a constant within a subroutine

    Hi,
    Yes, we can define a constant within a subroutine.
    perform f_check_company_code.
    form f_check_company_code.
    constant : lv_bukrs like bsis-bukrs value '1000'.
    loop at itab.
      if itab-bukrs = lv_bukrs.
        delete itab.
        clear itab.
      endif.
    endloop.
    Thanks,
    Sriram POnna.
    endform

  • Audio playback from within a state machine without halting execution

    I have created a state machine that acquires and analyzes an input signal and transitions states based on triggers detected within that signal.  In one particular state I need to play back a prerecorded file (right now I am just using a .wav file for testing purposes).  I understand that due to the data flow model the state machine hangs up during the playback state until the playback is finished, but I need to find someway around this.  Obviously, whenever the machine hangs up it cannot continue acquiring and analyzing the signal.  How can I start the playback from within the state machine without halting its execution?
    Solved!
    Go to Solution.

    Do you use the sound output VIs? If you do, try this. On the "Play Sound File VI" set the timeout value=0
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • SET CHAINED command not allowed within multi-statement transaction

    Hi,
    i need to do one transaction and i am setting autocommit(false) and
    once i am don ewith my 2 inserts i am settins it to true.
    i have like 20 thousand rows and when it is working fine for some inserts but after that it is throwing
    "SET CHAINED command not allowed within multi-statement transaction".
    can anyone please help me.

    You can find some information here:
    http://publib.boulder.ibm.com/infocenter/wsphelp/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rtrb_dsaccess.html
    it's first problem for sybase DB

  • What's the difference between defining a Thread within a class and....

    Guys,
    I am really confused when it comes to thread.
    What's the difference between defining a Thread within a class and implementing a Thread in a class?
    I just want to know about this. What is the difference between the two code classes?
    public class A
    public A()
    public Start()
    Thread th = new Thread():
    th.start(this);
    public class A extends Thread
    public A()
    *{*{code}*}*  
    *public Start()*
    *run();*

    My Googling show that the E/A may be a little newer but it appears that the E/A was not originally sold in the USA. The E/A appears to be sold in a Spanish speaking country.

  • Sybase:  SET CHAINED command not allowed within multi-statement transaction

    Hello,
    I'm getting the error message "SET CHAINED command not allowed within
    multi-statement transaction" for CMP Entity beans against Sybase.
    The errors appear in my jdbc.log in this order:
    010SM: This database does not support the initial proposed set of
    capabilities, retrying.) SQLState(010SM)
    JZ0EM: End of data.
    JZ0SJ: Metadata accessor information was not found on this database.
    Please install the required tables
    as mentioned in the jConnect documentation.
    010SL: Out-of-date metadata accessor information was found on this
    database. Ask your database administrat
    or to load the latest scripts.) SQLState(010SL)
    SQLState(ZZZZZ) vendor code(226)
    com.sybase.jdbc2.jdbc.SybSQLException: SET CHAINED command not allowed
    within multi-statement transaction.
    I'm using JConnect 5.5, WebLogic 6.1 sp3, Solaris 8, and Sybase 11.
    The weird thing is, the app works on a box running 6.1 sp2 and Win2k
    Prof.
    Any ideas?
    Thanks!
    Dan

    Hi Dan,
    There is a patch for this sybase problem, please contact [email protected] to
    get a temp patch.
    sree
    "Dan Blaner" <[email protected]> wrote in message
    news:[email protected]..
    Hello,
    I'm getting the error message "SET CHAINED command not allowed within
    multi-statement transaction" for CMP Entity beans against Sybase.
    The errors appear in my jdbc.log in this order:
    010SM: This database does not support the initial proposed set of
    capabilities, retrying.) SQLState(010SM)
    JZ0EM: End of data.
    JZ0SJ: Metadata accessor information was not found on this database.
    Please install the required tables
    as mentioned in the jConnect documentation.
    010SL: Out-of-date metadata accessor information was found on this
    database. Ask your database administrat
    or to load the latest scripts.) SQLState(010SL)
    SQLState(ZZZZZ) vendor code(226)
    com.sybase.jdbc2.jdbc.SybSQLException: SET CHAINED command not allowed
    within multi-statement transaction.
    I'm using JConnect 5.5, WebLogic 6.1 sp3, Solaris 8, and Sybase 11.
    The weird thing is, the app works on a box running 6.1 sp2 and Win2k
    Prof.
    Any ideas?
    Thanks!
    Dan

  • AND within IF statement in XML publisher

    Hi All,
    I am in need to use AND condition within an IF statement in rtf template.
    Here is the condition I am using
    <if:../../DIST_SHIPMENT_COUNT!=1 AND ../../ADDRESS_DETAILS/ADDRESS_DETAILS_ROW/LOCATION_ID!=SHIP_TO_LOCATION_ID?>
    My data
    <?end if?>
    This is not working, does anybody know how to achieve this.
    Appreciate your time and help.
    Thanks,
    Ragul

    so you mean to say
    ../../DIST_SHIPMENT_COUNT!=1 AND ../../ADDRESS_DETAILS/ADDRESS_DETAILS_ROW/LOCATION_ID!=SHIP_TO_LOCATION_ID
    and
    DIST_SHIPMENT_COUNT!=1 and LOCATION_ID!=SHIP_TO_LOCATION_ID
    conditions are different?
    exactly
    I have always refered to data elements in the RTF without giving any path and it works fine for me. is there anything that I may be missing?
    so you may be have simple case or may be not need to use parent tags logic
    so crazy example
    <ROWSET>
        <G2>
            <DIST_SHIPMENT_COUNT>0</DIST_SHIPMENT_COUNT>
            <ADDRESS_DETAILS>
                <ADDRESS_DETAILS_ROW>
                    <LOCATION_ID>2</LOCATION_ID>
                </ADDRESS_DETAILS_ROW>
            </ADDRESS_DETAILS>
            <G1>
                <ROW>
                    <SOMEROW>some text 1</SOMEROW>
                    <DIST_SHIPMENT_COUNT>1</DIST_SHIPMENT_COUNT>
                    <LOCATION_ID>3</LOCATION_ID>
                    <SHIP_TO_LOCATION_ID>3</SHIP_TO_LOCATION_ID>
                </ROW>
                <ROW>
                    <SOMEROW>some text 2</SOMEROW>
                    <DIST_SHIPMENT_COUNT>1</DIST_SHIPMENT_COUNT>
                    <LOCATION_ID>3</LOCATION_ID>
                    <SHIP_TO_LOCATION_ID>3</SHIP_TO_LOCATION_ID>
                </ROW>
            </G1>
        </G2>
    </ROWSET>
    and
    original condition:
    <?for-each:ROW?><?position()?> and value <?if: ../../DIST_SHIPMENT_COUNT!=1 and ../../ADDRESS_DETAILS/ADDRESS_DETAILS_ROW/LOCATION_ID!=SHIP_TO_LOCATION_ID?><?SOMEROW?><?end if?><?end for-each?>
    your condition:
    <?for-each:ROW?><?position()?> and value <?if: DIST_SHIPMENT_COUNT!=1 and LOCATION_ID!=SHIP_TO_LOCATION_ID?><?SOMEROW?><?end if?><?end for-each?>
    and result as
    original condition:
    1 and value
    some text 1
    2 and value
    some text 2
    your condition:
    1 and value
    2 and value

  • Function within SELECT statement

    Help please...
    How can I get the my custom RFCal function to work within
    this select statement??
    My Error:
    The value SUM((a2.act_rate + a2.act_gratuity) *
    ap2.actpac_quantity) cannot be converted to a number.
    My Code:
    SELECT outer select blah blah,
    (SELECT #RFCal("SUM((a2.act_rate + a2.act_gratuity) *
    ap2.actpac_quantity)" + p2.pac_serviceFee, p2.pac_occupancy)#
    FROM tablep2 p2 INNER JOIN tableap2 ap2 ON p2.pac_id =
    ap2.pac_id
    INNER JOIN tablea2 a2 ON ap2.act_id = a2.act_id
    WHERE p2.pac_id = p.pac_id) AS myTotal
    FROM tablep p INNER JOIN tableap ap ON p.pac_id = ap.pac_id
    INNER JOIN tablea a ON ap2.act_id = a.act_id
    WHERE outer select blah blah

    Thanks for responding Dan.
    Your option of running the function on the result via a
    cfloop is what I am currently doing... problem is I want to be able
    to sort the function result. So with that, what would be the
    simplest method?
    I will test running an additional query of queries on the
    result.

  • Calling a user defined function in a select statement

    PLS-00231: function 'F_GET_PROJECT_ID' may not be used in SQL
    I am caling a user defined function 'F_GET_PROJECT_ID' in a select statement and getting the above error .
    Can any one help me to resolve it.
    I can not replace the function with a local variable nor can I assign the output of the function to a variable and use the variable in the sql stmt. cos, the in put parameters of the function comes from the same select statement.
    Please help
    Thanks in advance

    Can you provide your function code? Using a function like that is possible from the below example. I suspect something in your function code.
    SQL> create or replace function sample_func(p_sal number)
      2  return number
      3  is
      4  v_sal number;
      5  begin
      6     v_sal := p_sal+100;
      7     return v_sal;
      8  end;
      9  /
    Function created.
    SQL>
    SQL> select empno, ename, sal, sample_func(sal)
      2  from emp
      3  /
         EMPNO ENAME             SAL SAMPLE_FUNC(SAL)
          7839 KING             5000             5100
          7698 BLAKE            2850             2950
          7782 CLARK            2450             2550
          7566 JONES            2975             3075
          7654 MARTIN           1250             1350
          7499 ALLEN            1600             1700
          7844 TURNER           1500             1600
          7900 JAMES             950             1050
          7521 WARD             1250             1350
          7902 FORD             3000             3100
          7369 SMITH             800              900
          7788 SCOTT            3000             3100
          7876 ADAMS            1100             1200
          7934 MILLER           1300             1400
    14 rows selected.
    SQL>And yeah... your formatted code is this.
    cursor c1 is
       SELECT t.upi_nbr upi_nbr,
              f_get_project_id(l.pay_type_code,
                               l.charge_type_nme,
                               l.charge_code) project_id,
              LAST_DAY(TO_DATE(SUBSTR(t.Year_Month, 5, 2)||'/'||'01'||'/'||SUBSTR(t.Year_Month,1,4),
                               'MM/DD/YYYY'))reporting_period_end_date,
              SUM (c.hours_worked_qty) reported_hrs
       from trs.trs_timesheet@oraprod5 T,
            trs.trs_line@oraprod5 L,
            trs.trs_cell@oraprod5 C
    where T.upi_nbr=L.upi_nbr
    and T.year_month=L.year_month
    and L.row_nbr=C.row_nbr
    and L.upi_nbr=C.upi_nbr
    and L.year_month = C.year_month
    and L.invalid_activity_ind = 'V'
    and rtrim(L.charge_code) is not null
    AND L.Pay_Type_Code<>'REQ'
    and C.Hours_Worked_Qty > 0
    GROUP BY t.upi_nbr,
             t.year_month,
             t.oui_nbr,
             l.charge_code,
             l.activity_detail_code,
             l.charge_type_nme,
             l.pay_type_code;Cheers
    Sarma.

  • Interactive pdf - Buttons within multi-state objects

    Hi,
    I seem to have a problem. I dont know if it is even possible, but I made a button that goes to a status of 2 multi-state objects. Within one of those multi-state objects is a button that closes that multi-state object. So now I am wondering if it is possible to make that same button close the other multi-state object aswell?
    Marc

    Yes, you can attach multiple actions to one button, but there´s a bigger problem... based on your title I guess you are trying to use multistate objects with interactive PDF and that´s not possible. MSOs are supported only with SWF exports and with Adobe DPS / Folios....

  • Draft Information within a Statement

    We are looking into the Statement Notification Refresh Program (R03B500X) and within the Processing Options you need to specify which Print Program to use.
    One of the options is the R03B5006 - Statement Print with Draft
    The description I found on that Statement Print was - This is the statement print program that you use when you want to include draft information.
    Question: What is draft information?

    Yes, a lot of data!
    It's interesting that you can write even more (I wrote about 1 Mb),
    but everything over 4,854 is flushed during the save.
    http://indisnip.wordpress.com/2010/07/31/saving-script-data-within-document/#comment-511
    Marijan (tomaxxi)

  • USING INDEXES DEFINED ON TABLES IN SELECT STATEMENTS

    Hi there,
    I would like to ask a simple question, how i can use indexes defined on certain columns on one of my database tables in a select clause:
    table name: B2TECDOC
    schema name: AWDBT1M4
    indexes defined: AWDBT1M4.B2TECDOC_B2TECDOCKEY
    index AWDBT1M4.B2TECDOC_B2TECDOCKEY is defined on columns:
    documentname
    documenttype
    organizationid
    organizationtype
    revision
    sequence
    versionnumbercould you help me construct a select sql using this index?
    another question is will using this index in my select clause increase the overall query performance?
    thanks
    rohan

    A query like
    SELECT *
      FROM AWDBT1M4.B2TECDOC
    WHERE documentname = <<some value>>
       AND documenttype = <<some value>
       AND organizationid = <<some value>>
       AND organizationtype = <<some value>>
       AND revision = <<some value>>
       AND sequence = <<some value>>
       AND versionnumber = <<some value>>should use the index.
    An index is a more efficient way to access a relatively small fraction of the rows in the table. A table scan will be more efficient if you are trying to access a relatively large fraction of the rows in the table. Exactly what "small fraction" and "large fraction" means will depend on a variety of factors that the cost-based optimizer (CBO) attempts to evaluate in determing the query plan.
    Justin

Maybe you are looking for

  • Books imported from previous version of iPhoto

    We have recently bought a new iMac and installed iLife 09. We imported the iPhoto Library from our old G4 iBook which was iPhoto Version 5.0.4. The import went well, except that this new version of iPhoto has completely different themes for books. SO

  • LOADER COMPONENT ISSUE

    I noticed that when using the Loader component in Flash 8 - the following issue: I have a thumbnail gallery that uses the Loader component to view the large image. when i view the site in fire fox it works perfectly (scaling the content and centering

  • How to control system fan

    are there any programs out there to control the speed of the system fan, or am i stuck with what the motherboard wants? 875P

  • Where are Home, End, Page Up, Page Down on MBP keyboard?

    I just bought a MBP-15 after spending my entire computer life with Windows.  I have a fairly sophisticated spreadsheet that I created in Excel that I now want to use in Numbers.  But I'm hung up on the simplest thing - Home & End.  I've read other po

  • Out put contact sheet to disc

    Need help on outputting (print template) contact sheets to disc to send to my lab. I am using a pc xp operating systems. Thanks for your help