How do I use multiple classes to print out different results

I tried the below, but it only printed the print line from the class that contains the "main" method, but I want the second one (Demo2) to print to check some logic :
class StaticDemo {
int x;
static int y;
class Demo {
public static void main(String args[]){
StaticDemo.y = 30;
System.out.println("StaticDemo.y = " + StaticDemo.y);
class Demo2 {
public static void main(String args[]){
System.out.println("StaticDemo.y 2 = " + StaticDemo.y);
}

You can only have one main method. Try something like this:
class StaticDemo
   int x;
   static int y;
class Demo
   public static void main(String[] args) {
      StaticDemo.y = 30;
      System.out.println("StaticDemo.y = " + StaticDemo.y);
      Demo2 d2 = new Demo2();
      d2.display();
class Demo2
   void display() {
      System.out.println("StaticDemo.y 2 = " + StaticDemo.y);

Similar Messages

  • Use same report to print out different data sources on the fly.

    Post Author: Lady101
    CA Forum: Data Connectivity and SQL
    We have 10 reports use diferent datasource( use views with different joint tables), but their print out format are identical. Is there a way to just use single report to run those 10 reports dynamically(the report can point to the right data source on the fly)? So that we can just change single report format when report format needs to be changed. Right now we have to change 10 reports format one by one.

    Another option would be to make a single pass in the Source Monitor and save a bunch of subclips. Here's a thread discussing keyboard workflows: Re: Question on making many Subclips in a fast way
    If you name highlights with one base name and lowlights with another, it would be easy to drop each batch into its own sequence.

  • How do I use multiple classes to access the same object?

    This should be staightforward. I have and object and I have multiple GUIs which operate on the same object. Do all the classes creating the GUIs need to be inner classes of the data class? I hope this question makes sense.
    Thanks,
    Mike

    public final class SingletonClass {
    private static SingletonClass instance;
    private int lastIndex = 10;
    public final static SingletonClass getInstance()
    if (instance == null) instance = new SingletoClass();
    return instance;
    public int getLastIndex() {
    return lastIndex;
    }1) This won't work since one could create a new SingletonClass. You need to add a private constructor. Also, because the constructor is private the class doesn't have to be final.
    2) Your design isn't thread-safe. You need to synchronize the access to the shared variable instance.
    public class SingletonClass {
        private static SingletonClass instance;
        private static Object mutex = new Object( );
        private int lastIndex = 10;
        private SingletonClass() { }
        public static SingletonClass getInstance() {
            synchronized (mutex) {
                if (instance == null) {
                    instance = new SingletonClass();
            return instance;
        public int getLastIndex() {
            return lastIndex;
    }if you are going to create an instance of SingletonClass anyway then I suggest you do it when the class is loaded. This way you don't need synchronization.
    public class SingletonClass {
        private static SingletonClass instance=new SingletonClass();
        private int lastIndex = 10;
        private SingletonClass() { }
        public static SingletonClass getInstance() {
            return instance;
        public int getLastIndex() {
            return lastIndex;
    }If you don't really need an object, then you could just make getLastIndex() and lastIndex static and not use the singleton pattern at all.
    public class SingletonClass {
        private static int lastIndex = 10;
        private SingletonClass() { }
        public static int getLastIndex() {
            return lastIndex;
    }- Marcus

  • How to use multiple classes for each form

    Hi,
    I have created two forms using screen painter and now i want to use different classes for these two forms .
    I have declared the Sbo Connection in main class i.e. Set Application ,Connection Context() but while connecting to other classes
    for executing the code for that form SAP is not connected to that class.How to use multiple classes functionality i don't able to
    do that.Please provide some sample codes for that as it will be more helpful for me to understand.
    Thanks & Regards,
    Amit

    Hi Amit,
    In fact, its more advisable to use separate classes for every form that you use.  Have one common class, say, for eg., clsMain.cs which has all the connection and connectivity to other classes, wherein, the menu event and item event of this main class, will just be calling the menu / item event of other classes.
    The individual functionality of the child classes will be called from the item / menu event of the respective classes.
    Item event in clsMain.cs will be as below.
    private void oApplication_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
                SAPbouiCOM.Form oForm;
                BubbleEvent = true;
                try
                    if ((pVal.FormTypeEx == "My_Form1Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm1_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
                    if ((pVal.FormTypeEx == "My_Form2Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm2_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
    Now, in the individual classes, you can have their respective item events, which will be called from the main class, and the respective functionalities will occur.
    Hope this helps.
    Regards,
    Satish.

  • How can I use multiple row insert or update into DB in JSP?

    Hi all,
    pls help for my question.
    "How can I use multiple rows insert or update into DB in JSP?"
    I mean I will insert or update the multiple records like grid component. All the data I enter will go into the DB.
    With thanks,

    That isn't true. Different SQL databases have
    different capabilities and use different syntax, That's true - every database has its own quirks and extensions. No disagreement there. But they all follow ANSI SQL for CRUD operations. Since the OP said they wanted to do INSERTs and UPDATEs in batches, I assumed that ANSI SQL was sufficient.
    I'd argue that it's best to use ANSI SQL as much as possible, especially if you want your JDBC code to be portable between databases.
    and there are also a lot of different ways of talking to
    SQL databases that are possible in JSP, from using
    plain old java.sql.* in scriptlets to using the
    jstlsql taglib. I've done maintenance on both, and
    they are as different as night and day.Right, because you don't maintain JSP and Java classes the same way. No news there. Both java.sql and JSTL sql taglib are both based on SQL and JDBC. Same difference, except that one uses tags and the other doesn't. Both are Java JDBC code in the end.
    Well, sure. As long as you only want to update rows
    with the same value in column 2. I had the impression
    he wanted to update a whole table. If he only meant
    update all rows with the same value in a given column
    with the same value, that's trivial. All updates do
    that. But as far as I know there's know way to update
    more than one row where the values are different.I used this as an example to demonstrate that it's possible to UPDATE more than one row at a time. If I have 1,000 rows, and each one is a separate UPDATE statement that's unique from all the others, I guess I'd have to write 1,000 UPDATE statements. It's possible to have them all either succeed or fail as a single unit of work. I'm pointing out transaction, because they weren't coming up in the discussion.
    Unless you're using MySQL, for instance. I only have
    experience with MySQL and M$ SQL Server, so I don't
    know what PostgreSQL, Oracle, Sybase, DB2 and all the
    rest are capable of, but I know for sure that MySQL
    can insert multiple rows while SQL Server can't (or at
    least I've never seen the syntax for doing it if it
    does).Right, but this syntax seems to be specific to MySQL The moment you use it, you're locked into MySQL. There are other ways to accomplish the same thing with ANSI SQL.
    Don't assume that all SQL databases are the same.
    They're not, and it can really screw you up badly if
    you assume you can deploy a project you've developed
    with one database in an environment where you have to
    use a different one. Even different versions of the
    same database can have huge differences. I recommend
    you get a copy of the O'Reilly book, SQL in a
    Nutshell. It covers the most common DBMSes and does a
    good job of pointing out the differences.Yes, I understand that.
    It's funny that you're telling me not to assume that all SQL databases are the same. You're the one who's proposing that the OP use a MySQL-specific extension.
    I haven't looked at the MySQL docs to find out how the syntax you're suggesting works. What if one value set INSERT succeeds and the next one fails? Does MySQL roll back the successful INSERT? Is the unit of work under the JDBC driver's control with autoCommit?
    The OP is free to follow your suggestion. I'm pointing out that there are transactions for units of work and ANSI SQL ways to accomplish the same thing.

  • How do you use multiple outputs on a VSTi like Kontakt or Battery?

    how do you use multiple outputs on a VSTi like Kontakt or Battery with Logic Pro 7.1? I've heard someting about using AUX busses, but can anyone please provide an actual clear, step by step basic guide?
    I've had Logic 3 months now and just don't know how to do this yet, and have yet to actually find it in the manual!!
    thx

    http://www.sonikmatter.com/wiki/index.php/Tutorial:MultiChanAudioSetup

  • How Can I Use Multiple Weblogic Instances in a Single OS

    Hello Everyone,
    Actually I have to install Some different applications. Few of them need weblogic 10.3.6 and others need 10.3.4. The OS am using is Oracle  Enterprise Linux 5.
    Now I am able to install 2 separate(One of 10.3.4 and 10.3.6) instances with two different users,In two different directories.
    I have installed the weblogic 10.3.6 version with a user webadmin and installed node manager with port 5556. This is working fine.
    The main problem here is :
    In the second instance (10.3.4 ) installed with a a different user and gave the port number to NodeManager as 1600 and its not getting started. Its throwing error and also after some errors in the terminal am able to see that its reverting to port number 5556 only.
    What might be the issue?
    I have to install 2 different versions of weblogic in a single Server. But am failing with NodeManager. What Can I do to have multiple weblogic instances with multiple versions in a single server ?
    Can anyone suggest a resolution for this please ?
    Thanks in advance.

    Pl do not spam these forums with multiple posts - How Can I Use Multiple Weblogic Instances in a Single OS

  • When I try to print a 4X6 photo using Elements 12 it prints out 2X3.  Does anyone know how you can get hold a live person at Adobe?

    When attempting to print a 4X6 photo using Elements 12 it prints out 2X3.  Does anyone know how you can get hold of a live person at Adobe?

    I've never done a forum and am not exactly sure what to do from here.   I
    know how to do a screen shot on my phone, but not on my computer. 
    I'm about ready to throw every adobe product I have out the window!   If
    you purchase a product you should be able to get support from the  company.
    In a message dated 4/6/2015 3:04:02 P.M. US Mountain Standard Time, 
    [email protected] writes:
    When  I try to print a 4X6 photo using Elements 12 it prints out 2X3.  
    Does anyone know how you can get hold a live person at Adobe?
    created by Peru Bob (https://forums.adobe.com/people/Peru+Bob)  in 
    Photoshop Elements - View the full  discussion
    (https://forums.adobe.com/message/7412463#7412463)

  • In Numbers '09, version 2.3 (554), how to I get spreadsheet gridlines to print out? I have a Macbook Pro and use OSX 10.9.4 Mavericks.

    In Numbers '09, version 2.3 (554), how to I get spreadsheet gridlines to print out? I have a Macbook Pro and use OSX 10.9.4 Mavericks.

    HP,
    In Numbers '09, the only lines that print are Cell Borders. Apply borders and test by Printing to PDF.
    Jerry

  • How can we use multiple transactions by using bdc_insert.

    HI
    How can we use multiple transactions by using bdc_insert.

    Hi,
    In between the Open and Close we have to use the BDC_INSERT for the Tcodes you have to do.
    BDC_OPEN_GROUP
    BSD_INSERT
    TCODE = tcode1
    BDC_INSERT
    TCODE = tcode 2
    BDC_CLOSE_GROUP
    check the SDN for more on this.
    Regards
    Lekha

  • How do I print out the results of a "search" or "find"?

    I used ical's "find" or "search" field to look up all calendar entries for a project I was working on. How do I print out this result? This is basically the information in the lower right box after you do a search.

    Dear Bri81,
    Thank you for your reply.
    I tried the coding as you suggested
    while(i.hasNext())
    System.out.println( i.next() );
    but the error message reads:
    "CD.java": Error #: 354 : incompatible types; found: void, required: java.lang.String at line 35
    Your help is appreciated
    Norman
    import java.util.*;
    public class TryCD
       public static void main(String[] args)
         Vector cdVector = new Vector();
         CD cd_1 = new CD("Heavy Rapper", "Joe", true);
         CD cd_2 = new CD("Country Music", "Sam", true);
         CD cd_3 = new CD("Punk Music", "Mary", true);
         cdVector.add(cd_1);
         cdVector.add(cd_2);
         cdVector.add(cd_3);
         Iterator i = cdVector.iterator();
         while(i.hasNext())
           System.out.println( i.next() );
    public class CD
       private String item;
       private boolean borrowed = false;
       private String borrower = "";
       private int totalNumberOfItems;
       private int totalNumberOfItemsBorrowed;
       public CD(String item,String borrower, boolean borrowed)
         this.item = item;
         this.borrower = borrower;
         this.borrowed = borrowed;
       public String getItem()
         return item;
       public String getBorrower()
         return borrower;
       public boolean getBorrowed()
         return borrowed;
       public String toString()
          return System.out.println( getItem() + getBorrower());

  • How do I get my MX420 to print out a fax that is in its memory?

    How do I get my MX420 to print out a fax that is in its memory?

    Hello notatechie,
    Please try the following procedure to print the documents in memory:
    1. Make sure that the machine is turned on.
    2. Load paper.
    3. Press the FAX button.
    The Fax standby screen is displayed.
    4. Press the left Function button.
    The Fax menu screen is displayed.
    5. Select  Memory reference, then press the OK button.
    6. Use the   button to select Print all received documents, then press the OK button.
    The confirmation screen is displayed.
    7. Use the   button to select Yes, then press the OK button.
    All the documents in machine's memory will be printed.
    Each time a document is printed, the screen to confirm whether to delete the printed document in machine's memory is displayed.
    If you select Yes using the   button and press the OK button, the printed document in machine's memory is deleted.
    We hope this helps!
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • HT204364 how do I order multiple card or postcard with different images each one in same order?

    how do I order multiple card or postcard with different images each one in same order?
    I keep paying separate shipping cost for each different photo

    That is not an option - with the exeption of photo prints you can only identical items on one order
    LN

  • How can I use one gmail address on two different macbooks in 'mail'?

    I'm using one business gmail address. Me and my girlfriend both have a macbook. Now the gmail address is linked to my macbook. But she wants to use it as well. Unfortunately the 'mail' system won't allow her to sync with the gmail address. And I get messages from gmail saying that someone tried to log in to my account. Which is something I certainly want, but can't change. Does anyone now how I can use 1 gmail address on two different mac's? Thanks

    You may be able to change the suspicious account activity message alerts
    in your Gmail settings, and check that side of it, since I can use several
    means of accessing my Gmail and Google Accounts; and in the past had
    shared an account (not google) with another party half a world away when
    her email server went down for a month.
    The Mail software should not know the difference, unless the setup in there
    is not correct; if this is so, then more than what she says would be wrong.
    The Google mail Support help site pages should cover this adequately.
    Gmail Help - Google Help
    https://support.google.com/mail/?hl=en

  • HT204053 How do I use the same Apple ID and different Cloud for other devises

    Hi
    How do I use the sane Apple ID and different Icloud for other devises

    http://support.apple.com/kb/HT4627

Maybe you are looking for

  • W540 Windows 8.1 install from scratch (ssd)

    Hi, Lenovo user's I need your help. My new W540 need to be rebuild (win 8.1) from scratch and manual driver,s install. Ok it's rediculus, but my manager at work need that test. I buy the original 2 dvd's ( #1 recovery disk media and #2 operating syst

  • J2EE download...

    I downloaded the Web Services Development Pack 1.1 and installed it onto my machine thinking that it was the J2EE SDK 1.3... however, whilst following the instructions for setting up from the SUN site I found that my installation did not include a J2

  • How to cover the new in Java 5

    Hi java community :) I am a Java programmer since 4 years which means that I worked with 1.3 then with 1.4 and there was no big difference betwen them. But, with Java 1.5 I think I need some articles or tutorials that explain what are the differnces

  • Unknown error on iPad 2

    Dear All For some reason I have been unable to download any updates or purchases from App Store/iTunes. When I put in the correct ID it comes up with Unknown Error, no specifc code. I have changed my apple ID twice and this hasnt worked. I have also

  • Problem Facing on Iphone

      After I update to IOS 7, my iphone automatic appear several application that I had deleted long long time ago in the grey colour condition. Sometime it display waiting under the app and sometime it don't. When I click 'x' and delete, it do not have