Results 1 to 2 of 2
  1. #1
    phanikumar is offline Member
    Join Date
    Jun 2015
    Rep Power

    Default creating object in static block

    Hi can any one tell me the line by line execution of below code.
    I am not able to understand the execution of static block of D1 class.
    Please help me by giving detailed explanation.

    class C1
    public static void main(String args[])
    D1 d=new D1();
    System.out.println("this is main"+d.a);
    class D1
    int a=10;
    String a="JAVA";
    D1 d=new D1();
    System.out.println("This is Instance Block"+a+"\t"+d.a);

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: creating object in static block

    Go through BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    Still cross posting: Java Forums at the Big Moose Saloon

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Static Block in java executes first
    By rdehankar in forum New To Java
    Replies: 2
    Last Post: 03-21-2014, 02:20 PM
  2. What is the use of Static method and static block
    By chandrasekhar.melam in forum New To Java
    Replies: 7
    Last Post: 08-20-2013, 02:44 PM
  3. Static Block and variable problem
    By phobosforever in forum New To Java
    Replies: 1
    Last Post: 07-04-2011, 01:28 PM
  4. Replies: 2
    Last Post: 11-16-2010, 05:51 PM
  5. [SOLVED] static block or constructor?
    By JT4NK3D in forum New To Java
    Replies: 3
    Last Post: 05-27-2008, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts