7.15 Count Number of Objects of Class in Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 124

  • @vishnupriyaa5146
    @vishnupriyaa5146 6 ปีที่แล้ว +4

    Sir, I am a CSE final year student. I am learning Java from your videos. I feel very much comfortable to learn from your lectures and practical demos. Thank you so much for the clear explanations and apt examples. I have a book titled 'How to crack Interviews in Java' written by Rashmi Kanta Das. It has only questions and one word answers without explanations. Can you please upload videos with explanations for the answers in that book?

  • @b041_dt_shubham_guptagupta9
    @b041_dt_shubham_guptagupta9 5 ปีที่แล้ว +7

    Thanks for the answer sir, I was asked this question in my technical interview and you explained it very well😘

  • @tocsashwin
    @tocsashwin 8 ปีที่แล้ว +2

    Excellent tutorial sir. this is what I had been searching for so many days. Perfect explanation and you explain so nicely that anyone who are really new to Java can also understand. This is a real compliment from my heart. Keep up the work. You are doing a great job helping out young engineers like us learn and get ourselves mastered with Java.

  • @pratikgudsurkar8892
    @pratikgudsurkar8892 7 ปีที่แล้ว +28

    we want more interview questions

  • @sudiptomukherjee8404
    @sudiptomukherjee8404 5 ปีที่แล้ว +3

    I became your fan and the way of your e explanation is awesome.keep it up

  • @ReenaSharma-wu8ky
    @ReenaSharma-wu8ky 5 ปีที่แล้ว

    Best java teacher in the world.

  • @TechWek1
    @TechWek1 2 ปีที่แล้ว

    This type of questions is very important and help me to understand the concept
    Please upload more videos like this thank you 🙏🙏

  • @barath9815
    @barath9815 7 ปีที่แล้ว

    sir give static that will not replace the value of i .....thank u so much ur videos are in proper order sir

  • @kiruthikas1073
    @kiruthikas1073 3 ปีที่แล้ว

    U r just an amazing person in this whole world!

  • @cyberguide_in
    @cyberguide_in 8 ปีที่แล้ว

    Hi Naveen Sir
    I have a few questions for you so could you please answer them through your tutorials? I am certainly not judging your knowledge in this subject but Just requesting you.
    1. Create a method which can take any kind of generic parameter.
    For instance: map, map, List.
    2. Can we use comparable in the catch block ? if so, then what would be the scenario?
    3. Can we use Object class in place of Throwable as it is a parent class?
    4. What the are the fastest map used in order to store billions of data?
    Regards

  • @sudharsansrini7057
    @sudharsansrini7057 4 ปีที่แล้ว +4

    One Mistake: Sir, You changed 'i' as static variable. So that can't be used in non static method sir. We have to put static in that class method sir.
    Otherwise all your videos are really awesome sir. I completed your Python tutorial. Now I'm going with Java. After Java Script. Thank you so much for your videos sir.

    • @arkopalchakraborty6154
      @arkopalchakraborty6154 4 ปีที่แล้ว +1

      That is not a non static method.That is a constructor. Public A() is a constructor.And constructor loads everytime an object is in play.
      If you are talking about that counter method which is non static then you are wrong.A non static method can access static variables or class variables.The vice versa is not possible.

    • @bittooaggarwal5776
      @bittooaggarwal5776 4 ปีที่แล้ว

      we can use static variable in non-static method if i am not wrong.

  • @abhilashbisht2840
    @abhilashbisht2840 6 ปีที่แล้ว +1

    dear sir, i have a doubt.. please clear
    variable 'i', being a non-static variable can't be used inside the count() as well as main() (as you told in the previous lectures), so it is obvious that it will not be compiled at first place and show error if we not make it static

  • @shadabkhans
    @shadabkhans 2 ปีที่แล้ว

    thanks for all your efforts.... great teaching sir

  • @ravinsr69
    @ravinsr69 5 ปีที่แล้ว +2

    i found it if we have parameterized constructor or method we have to declare i++ inside of that method also to get exact count

  • @nonnodacciaio704
    @nonnodacciaio704 2 ปีที่แล้ว

    Exactly what I needed

  • @rahulpradhan5585
    @rahulpradhan5585 5 ปีที่แล้ว

    Heartly speaking a big thank you.
    We want more interview questions sir

  • @sanisan5787
    @sanisan5787 5 ปีที่แล้ว +1

    We want more interview questions,coding questions,and mcqs(wer we must find Java output)

  • @techGenz-k6o
    @techGenz-k6o 5 ปีที่แล้ว +3

    public class A
    {
    static int i=0;
    A()
    {
    i++;
    }
    public static void main(String[] args)
    {
    A obj0=new A();
    A obj1=new A();
    A obj2=new A();
    A obj3=new A();
    System.out.println("Number of objects created:" +i);
    }
    }

  • @nithinj9102
    @nithinj9102 4 ปีที่แล้ว

    Please create more important and complex interview questions

  • @aakashbhardwaj476
    @aakashbhardwaj476 6 ปีที่แล้ว +1

    this is so complex. simply create the anonymous block.
    {
    i++; // if you do variation i--// you will -as prefix
    }
    done.

  • @sarbeshkumarsingh1328
    @sarbeshkumarsingh1328 7 ปีที่แล้ว +1

    good question show more like this....

  • @chandanaakriti540
    @chandanaakriti540 6 ปีที่แล้ว

    There is some simple mistakes in code.
    1) public static void counter ( instead of just public void counter)
    2) in main A.counter();
    (Last line instead of A obj.counter(); )
    Thanks 🙂

    • @lalitbindal7779
      @lalitbindal7779 5 ปีที่แล้ว

      but we can use a static variable inside a non static method

  • @SupremeDZ
    @SupremeDZ 2 ปีที่แล้ว

    Thanks for the answer sir

  • @anotherSportsCarEnthusiast
    @anotherSportsCarEnthusiast 5 ปีที่แล้ว

    Thanks for sharing your knowledge, I find these videos fun and entertaining.

  • @coolgirlsharu
    @coolgirlsharu 5 ปีที่แล้ว

    To became a Java developer ,
    Just core Java is enough,or
    We should know even advance Java like Jsp servlets , spring MVC

  • @prajaktakhandave3379
    @prajaktakhandave3379 4 ปีที่แล้ว

    Hi Naveen, can you please create series for UI Automation and Rest API Automation for QA

  • @greenbeecannabissimplified6631
    @greenbeecannabissimplified6631 4 ปีที่แล้ว

    Thank you sir!! This was very well explained and helpful!

  • @adityamehta2819
    @adityamehta2819 6 ปีที่แล้ว

    we can simply use instance of and then count

  • @suvasishsahoo2189
    @suvasishsahoo2189 7 ปีที่แล้ว

    Greatly explained!!

  • @lakshminarayansingh5485
    @lakshminarayansingh5485 5 ปีที่แล้ว

    Nice explanation

  • @rajeshkolli42
    @rajeshkolli42 3 ปีที่แล้ว

    Love this video!

  • @aviroxi
    @aviroxi 3 ปีที่แล้ว

    that's amazing thank you so much!!!

  • @hrishabhsoti4356
    @hrishabhsoti4356 7 ปีที่แล้ว

    sir
    in one of ur video "use of static block" u said constructor don't work on static variables but in this video its contradictory........
    plz explain this.....
    waiting for an early explanation....

    • @vishnupriyaa5146
      @vishnupriyaa5146 6 ปีที่แล้ว

      Actual use of static block :
      We can assign values (initial values) to static variables inside the static block similar to the way we assign values to non-static variables inside constructor. We can also assign values to static variables from constructor. But, the value will be assigned only after the first object of the class is created. And the same code (assignment statement) will be executed unnecessarily every time we create an object of that class.

  • @simranjeetsingh5807
    @simranjeetsingh5807 7 ปีที่แล้ว

    yes please make more videos on interview questions

  • @kumar17299
    @kumar17299 8 ปีที่แล้ว

    Hello Reddy i think you used to watch Nalamothu Sridhar videos, Because he is also same, In 2 mins with out any head and tail wants to say something.

  • @DeathBender
    @DeathBender 5 ปีที่แล้ว

    Yet you should "somehow" avoid/restrict access to your counter variable else one might simply change it back to 0 (A.i = 0) ;^) .

  • @shuvshaw9594
    @shuvshaw9594 5 ปีที่แล้ว

    // INTERVIEW QUESTION :- HOW TO KNOW HOW MANY OBJECTS ARE CREATED FOR AN CLASS?
    // SOLUTION: THERE IS AN CODE WHICH WILL FIND HOW MANY OBJECTS ARE CREATEING FOR TARGET CLASS.
    public static void main(String[] args) {
    target obj1=new target();//create object1
    target obj2=new target();//create object2
    target obj3=new target();//create object3
    target obj4=new target();//create object4
    target obj5=new target();//create object5
    target obj6=new target();//create object6
    target obj7=new target();//create object7
    obj2.counter();
    }
    }
    class target
    {
    public static void main(String[] args) {
    }// main method under this target class
    static int c; // class variable (by default any integer has value 0)
    public target() // constructer(which is create by default when we make any new object)
    {
    c++;//use to count
    }
    public void counter() // static use because the class variable is static
    {
    System.out.println(c);//print the counted value
    }
    }

  • @sjblackhawk9887
    @sjblackhawk9887 5 ปีที่แล้ว

    hi, Telusko , is there a way to use reflection to grt the count? here it is going to only show the instances created, but what abt instances no longer present because of GC.

  • @Abhishek-Vincent
    @Abhishek-Vincent 6 ปีที่แล้ว

    well explained!! thank you

  • @kesavareddy1476
    @kesavareddy1476 5 ปีที่แล้ว

    Hey Navin ,it's really nice yeah

  • @TheLastAvenger1000
    @TheLastAvenger1000 4 ปีที่แล้ว

    I love you bro

  • @maheshreddy7569
    @maheshreddy7569 6 ปีที่แล้ว

    Sir can u do a video on up casting and down casting

  • @W333dm4n
    @W333dm4n 4 ปีที่แล้ว

    amazing.

  • @raounak_sharma
    @raounak_sharma 8 ปีที่แล้ว +5

    Sir i have a question
    how can we do operation with a static member in a non static method? As you have done with 'i' variable.

    • @michal234486
      @michal234486 8 ปีที่แล้ว

      actually I wanted to ask the same

    • @shivamarora3812
      @shivamarora3812 7 ปีที่แล้ว +3

      Raounaq Sharma bro we can have a static variable inside a non-static method but it is necessary to have a static variable with static method..i hope this will clear your doubt

    • @prateeknima3388
      @prateeknima3388 7 ปีที่แล้ว +4

      That's a constructor and there is nothing like static constructor.

    • @manasranjan5232
      @manasranjan5232 6 ปีที่แล้ว

      Inside non static method we can use static variable..i.e [public void counter()] is correct....but we can't use static variable inside a constuctor... right?

    • @lalitbindal7779
      @lalitbindal7779 5 ปีที่แล้ว

      @@manasranjan5232 i think so

  • @ReenaSharma-wu8ky
    @ReenaSharma-wu8ky 5 ปีที่แล้ว

    Please do create a project on java.

  • @shreyanshjain2822
    @shreyanshjain2822 5 ปีที่แล้ว

    hello sir i really like your videos and they are very simple to understand also.....but sir i have recently given TCS interview and they asked me a question about an array ...How will you tell that the two array are similar without accessing the elements (or index). So sir if you can tell me about this it would be really great.. and Thanks for the videos.

    • @nitheeshreddy6863
      @nitheeshreddy6863 2 ปีที่แล้ว +1

      Convert both to string and use .equals or compare to

  • @DurgaShiva7574
    @DurgaShiva7574 5 ปีที่แล้ว

    Interviewer:->consider a simple class which has the following structure:-
    class A
    {
    int i;
    }
    and when you do, A obj1=new A();....
    HOW MANY OBJECTS ARE CREATED FROM the statement above..?
    I answered 1 , but he said i am wrong...
    the question was asked in an interview from me..please update with the correct answer ..really hoping to hear from you soon..

  • @gauravpande
    @gauravpande 7 ปีที่แล้ว

    Question 1 : How to use String with "for loop", not for each loop?
    Question 2: How to use String with the Switch statement?
    Thanks

    • @Someone-kw6mw
      @Someone-kw6mw 4 ปีที่แล้ว +2

      We can not use string as for each loop in java but u can do this
      String name = 'thfhsj'
      for (int i = 0; i< name.lenght(); i++)
      {
      System.out.println(name.indexOf(i))
      }

  • @niroshacharala1324
    @niroshacharala1324 4 ปีที่แล้ว

    No need to create objects for static variable right sir?

  • @prasoonkushwah9558
    @prasoonkushwah9558 6 ปีที่แล้ว

    incredible!

  • @siddharthsivanpillai4879
    @siddharthsivanpillai4879 7 ปีที่แล้ว

    superb

  • @jassikaur6180
    @jassikaur6180 5 ปีที่แล้ว

    Plz sir upload this type of interesting codes

  • @manoj__rawat
    @manoj__rawat 3 ปีที่แล้ว

    What about the parameterized constructor?

  • @gaatutube
    @gaatutube 5 ปีที่แล้ว

    What happens when an object is deleted (garbage collected). How do we decrement the "i" variable to keep accurate track of the CURRENT number of objects ?

  • @ujjawalkumar7913
    @ujjawalkumar7913 3 ปีที่แล้ว

    Sir can you plz explain this practically just by doing a program of it

  • @rohitpandey714
    @rohitpandey714 4 ปีที่แล้ว

    what if we are calling the constructor using super() or this(). No new object is created still value of counter will increment.

  • @ArjunSingh-qt5jn
    @ArjunSingh-qt5jn 8 ปีที่แล้ว

    thanx brother (y)

  • @thesuhail249
    @thesuhail249 7 ปีที่แล้ว +1

    package com.amatuer.java;
    public class CountObjects {
    public static void main(String[] args)
    {
    // Everytime we create an object we call one method which is constructor
    // In this case the Constructor is "Counter"
    Counter obj1 = new Counter(); // This will increment the value of i by 1
    // This new obj creates an instance in heap and holds the value 1
    Counter obj2 = new Counter(); // This new obj creates an instance in heap again and holds the value 1 again
    Counter obj3 = new Counter(); // This new obj creates an instance in heap again and holds the value 1 again
    Counter obj4 = new Counter(); // This new obj creates an instance in heap again and holds the value 1 again
    Counter obj5 = new Counter(); // This new obj creates an instance in heap again and holds the value 1 again
    // The reason being "i" is defined as an instance variable.
    // in order to hold the same value of "i" in every obj creation that whould be defined as static
    // Static/Class variable is a variable which shared among the objects
    obj5.Show();
    }
    }
    class Counter
    {
    static int i;
    public void Counter()
    {
    i++;
    }
    public void Show()
    {
    System.out.println("Number of objects in class CountObjects is " +i);
    }
    }

  • @kuku5567
    @kuku5567 5 ปีที่แล้ว +4

    Interview ques : How do i stop a user from creating more than two objects of a class ?

    • @Knightk0der
      @Knightk0der 4 ปีที่แล้ว

      Answer please

    • @Someone-kw6mw
      @Someone-kw6mw 4 ปีที่แล้ว +1

      See count the number of objects first
      Then put a if statement inside the class that if number of objects is more than two u have to make something that will create an error like there is an array of 5 elements and u will try to get 9th element of that and that will stop the user

    • @bittooaggarwal5776
      @bittooaggarwal5776 4 ปีที่แล้ว

      Good query, i will try it out tomorrow.

  • @assassinsquadgaming6565
    @assassinsquadgaming6565 8 ปีที่แล้ว

    sir, can you give us some more important questions for interview.

  • @kartheek.g3667
    @kartheek.g3667 8 ปีที่แล้ว

    how to reverse a given input string could you please explain with an example.
    please make video on Collectonsframwork I don't able to remember these concept even when read many times

  • @sreekarkambam5619
    @sreekarkambam5619 3 ปีที่แล้ว

    Class A and variable I should be static in order to count the number of objects.

  • @agustdik3696
    @agustdik3696 5 ปีที่แล้ว

    Make more interview questions

  • @techraja930
    @techraja930 5 ปีที่แล้ว

    Sir how many objlect should be created from one class please tell me or make vedio on it

  • @ankush2905
    @ankush2905 7 ปีที่แล้ว

    hii naveen , you told that constructor do not work on static variable .. But here i variable is static and then we are incrementing the value of that static variable (i) inside the constructor . How ????

    • @vishnupriyaa5146
      @vishnupriyaa5146 6 ปีที่แล้ว

      Actual use of static block :
      We can assign values (initial values) to static variables inside the static block similar to the way we assign values to non-static variables inside constructor. We can also assign values to static variables from constructor. But, the value will be assigned only after the first object of the class is created. And the same code (assignment statement) will be executed unnecessarily every time we create an object of that class.
      But here, we want to increment the static variable every time we create an object. So we give the increment statement inside the constructor.

  • @DeepakKumar-hn5tz
    @DeepakKumar-hn5tz 7 ปีที่แล้ว

    Sir plz upload a video regarding how to get the size of object in java

    • @DeepakKumar-hn5tz
      @DeepakKumar-hn5tz 7 ปีที่แล้ว

      can you tell me how

    • @DeepakKumar-hn5tz
      @DeepakKumar-hn5tz 7 ปีที่แล้ว

      I think you want to say the common algorithm jVM follows while allocating memory for the object in the heap when it calls the constructor(basically default) ,I know how to know the approx size.There is a way we can find the total size of object in writing one file in the classpath of the web application mainly in Batch Processing Application.Never say its not possible,Before saying not possible try to inspect got it.Plz go through the J2SE api.thnx

    • @DeepakKumar-hn5tz
      @DeepakKumar-hn5tz 7 ปีที่แล้ว

      stackoverflow.com/questions/52353/in-java-what-is-the-best-way-to-determine-the-size-of-an-object follow this and stop saying impossible

    • @DeepakKumar-hn5tz
      @DeepakKumar-hn5tz 7 ปีที่แล้ว

      Have u worked on JMon APi

  • @sumityadav6429
    @sumityadav6429 8 ปีที่แล้ว +2

    sir ,according to your method i have to add " i++" in every constructor . Is there any other way

    • @sairajdas6692
      @sairajdas6692 6 ปีที่แล้ว

      Sandeep Rawat but you need only 1 constructor

  • @hrithikroshan5823
    @hrithikroshan5823 4 ปีที่แล้ว

    can a static variable be used in a Constructor ??

  • @giveaway4002
    @giveaway4002 6 ปีที่แล้ว

    What is I make copy of one object to another object?Without calling the construction.

  • @Ravikumar-gj6qw
    @Ravikumar-gj6qw 6 ปีที่แล้ว

    I want hashmap internals pl teach it and Also sorting and data structures

  • @ravinsr69
    @ravinsr69 5 ปีที่แล้ว

    What if parameterized constructor in creation..?

  • @iotguru5911
    @iotguru5911 6 ปีที่แล้ว

    Sir do you have Android lectures? I am also ready to subscribe if you can give Android classes.

  • @thespark6785
    @thespark6785 8 ปีที่แล้ว

    but what to do if i have a parametrized constructor??

  • @OTFBYFK
    @OTFBYFK 4 ปีที่แล้ว

    Hi .can u tell me how to count the number of lines of a function

  • @Vivekrathoud
    @Vivekrathoud 7 ปีที่แล้ว

    but what is the class have multiple overloaded constructors ?

  • @kamrulhasanshahed6681
    @kamrulhasanshahed6681 8 ปีที่แล้ว

    how to decrease that variable when object destroyed?

  • @sairajdas6692
    @sairajdas6692 6 ปีที่แล้ว

    Sir can we make counter method as static ?

    • @vishnupriyaa5146
      @vishnupriyaa5146 6 ปีที่แล้ว +2

      yes, i tried it
      Code :
      public class ObjectCount {
      public static void main(String[] args) {
      Abc5.dispCount();
      Abc5 obj1=new Abc5();
      Abc5 obj2=new Abc5();
      Abc5 obj3=new Abc5();
      obj1.dispCount();
      Abc5 obj4=new Abc5();
      Abc5 obj5=new Abc5();
      Abc5.dispCount();
      Abc5 obj6=new Abc5();
      Abc5 obj7=new Abc5();
      Abc5 obj8=new Abc5();
      Abc5 obj9=new Abc5();
      obj9.dispCount();
      Abc5 obj10=new Abc5();
      Abc5 obj11=new Abc5();
      Abc5 obj12=new Abc5();
      Abc5.dispCount();
      }
      }
      class Abc5
      {
      static int count=0;
      Abc5()
      {
      count++;
      }
      static void dispCount()
      {
      System.out.println("No. of objects of Abc5 class ="+count);
      }
      }

  • @sudheermandi6135
    @sudheermandi6135 6 ปีที่แล้ว

    it works for only objects created by default constructor , if we create object by using param-const() it will not work , in that it is showing only the count of default constructor created objects only
    public class CountObject
    {
    static int i;
    public CountObject()
    {
    i++;
    }
    CountObject(int i )
    {
    System.out.println("came to param");
    // here also we need to increment i value if obj created by parameter-constructor
    }
    public static void main(String args[])
    {
    CountObject obj1 = new CountObject();
    CountObject obj2 = new CountObject();
    CountObject obj3 = new CountObject(10);
    System.out.println("No. of Objects: " + i);
    }
    }
    here I created 3 objects but it showing count 2 only

  • @shalinikhosla971
    @shalinikhosla971 3 ปีที่แล้ว

    Plese upload more videos

  • @sarbeshkumarsingh1328
    @sarbeshkumarsingh1328 7 ปีที่แล้ว

    thanks alote..........

  • @yashasvishukla6044
    @yashasvishukla6044 7 ปีที่แล้ว

    why main class is kept as static??
    And how main class is called without creating its object??

    • @mohitchauhan2401
      @mohitchauhan2401 7 ปีที่แล้ว

      Yashasvi Shukla you just answer your own question ...since main is static it does not require object creation to access variable or methods

  • @sanisan5787
    @sanisan5787 5 ปีที่แล้ว

    Why it will print 3 if it calls obj2?

    • @jaygohil7232
      @jaygohil7232 5 ปีที่แล้ว

      obj2.counter() will print 3 because all the objects are created before calling counter() method.

  • @mohamedthoufiqm8108
    @mohamedthoufiqm8108 ปีที่แล้ว

    ❤️

  • @kartheek.g3667
    @kartheek.g3667 8 ปีที่แล้ว

    I hope you know telugu because you said you are south indian. Is it rightl?

  • @nazminvahora3397
    @nazminvahora3397 3 ปีที่แล้ว

    👍

  • @petrovpiter4059
    @petrovpiter4059 8 ปีที่แล้ว +1

    package CountObj;
    public class CountObjects {
    public static void main(String[] args) {
    // @author Khamdamboy Urunov 25/08/2016
    Acount obj1 = new Acount();
    obj1.Countvalue();
    Acount obj2 = new Acount();
    obj2.Countvalue();
    Acount obj3 = new Acount();
    obj3.Countvalue();
    }
    }
    class Acount{
    /*
    * Instance variable is every time update copying value
    * that means i =0; next creating value also copying this value i=0;
    * */

    static int i; /*
    * instance variable when using variable without keyword static
    * we can use class variable keyword static....
    *
    */
    public Acount(){
    i++;
    }
    public void Countvalue()
    {
    System.out.println("Number of obj: " +i);
    }
    }

  • @SritharBoss
    @SritharBoss 6 ปีที่แล้ว

    Okay. What happens when we create an anonymous class...

  • @Sumanth1418
    @Sumanth1418 4 ปีที่แล้ว

    Can anyone give me full program for this...

  • @ALLROUNDER_-bh6vc
    @ALLROUNDER_-bh6vc 2 ปีที่แล้ว

    how to count total mobiles present on shopping websites????????????????/

  • @NishaMeenachocolover
    @NishaMeenachocolover 8 ปีที่แล้ว +2

    Hey,
    Can you please share the code for this as I am not able to get an output.

    • @ankitsaxenamusic
      @ankitsaxenamusic 8 ปีที่แล้ว

      class CountObject
      {
      static int i;
      public CountObject()
      {
      i++;
      }
      public static void main(String args[])
      {
      CountObject obj1 = new CountObject();
      CountObject obj2 = new CountObject();
      System.out.println("No. of Objects: " + i);
      }
      }
      //Output : No. Of Objects: 2

    • @yogesh.kharita
      @yogesh.kharita 8 ปีที่แล้ว

      First of all you are very beautyful and you can take my code : )class E
      {
      public static void main(String args[])
      {
      F obj=new F();
      F obj2=new F();
      F obj3=new F();
      F obj4=new F();
      obj4.counter();
      }
      }
      class F
      {
      static int i; //zero
      public F()
      {
      i++;
      }
      public void counter()
      {
      System.out.println(i);
      }
      }

  • @sushmaveldanda4051
    @sushmaveldanda4051 8 ปีที่แล้ว +1

    pls give us the code

    • @anotherSportsCarEnthusiast
      @anotherSportsCarEnthusiast 5 ปีที่แล้ว +1

      This should work:
      public class A {
      static int i;
      public A()
      {
      i++;
      }
      public void counter()
      {
      System.out.println(i);
      }
      public static void main(String[] args) {
      A obj1 = new A();
      A obj2 = new A();
      A obj3 = new A();
      obj3.counter();
      }
      }

    • @anotherSportsCarEnthusiast
      @anotherSportsCarEnthusiast 5 ปีที่แล้ว

      output will be 3

  • @rareangel15
    @rareangel15 4 ปีที่แล้ว

    I don't understand this video!