Top 10 Static & Instance Block Based Interview Questions || Tricky Java Interview Questions

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ต.ค. 2024
  • In this video, I have covered different Static Block Based Interview Questions || Tricky Java Interview Questions
    --static block
    --instance block
    /**
    Java Static Block Interview Questions:
    Q1. Explain static blocks in Java ?
    Q2. How can we run a java program without making any object?
    Q3. Similarity and Difference between static block and static method ?
    Q4. How can we create objects if we make the constructor private ?
    Q5. Is it possible to compile and run a Java program without writing main( ) method?
    Q6. Can we initialize member variables within static block ?
    */
    ~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    www.youtube.co...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
    t.me/joinchat/...
    Naveen AutomationLabs Paid Courses:
    Java & Selenium:
    naveenautomatio...
    Java & API +POSTMAN + RestAssured + HttpClient:
    naveenautomatio...
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @sridharlanka2721
    @sridharlanka2721 3 ปีที่แล้ว +32

    Give this man a medal🥇

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

      a trick : watch series on flixzone. I've been using it for watching a lot of movies during the lockdown.

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

      @Jon Russell yea, have been watching on flixzone} for since december myself :)

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

    These are the most common nd Basic part of java
    But people are confusing about it. Nd u explained it very Simply way. Thanks Naveen 😊

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

    15:00 It's because of the "final" keyword.
    If X was only static and not final, the static block would be called.
    Explaination in a layman's terms would be, if a variable is static and final, it means that it's shared between all objects and it's value cannot change, hence the compiler will simply put it's value in the calling statement instead of referencing it from the original class.
    If it was not final, means the value of x is changeable, therefore directly putting the value in the calling statement could cause inconsistencies.

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

      @Coder Toaster - many thanks 👍

  • @nikeshkumar-gl1fv
    @nikeshkumar-gl1fv 3 ปีที่แล้ว +3

    One of my favourite teacher, who used to give concepts from scratch . 🙏🙏

    • @nikeshkumar-gl1fv
      @nikeshkumar-gl1fv 3 ปีที่แล้ว +1

      Sir currently I got placed in COGNIZANT and my job role is SDET , initially they are giving internship where they are teaching java,SQL, spring framework, spring MVC, spring boot, selenium, HTML,css, Restful api, microservices and many more . And your tutorial is purely based on Sdet role . Thanks sir 🙏🙏🙏🙏🙏🙏🙏

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

    This is really very useful..Completely cleared my doubts. Thanks a lot for making such awesome videos.

  • @harekrishnasingh6874
    @harekrishnasingh6874 3 ปีที่แล้ว +1

    no more confusion on static block....thank u myguru....!!!!

  • @SumitSharma-qq4hk
    @SumitSharma-qq4hk 3 ปีที่แล้ว +3

    Awesome.... Everytime there is a video by you, I learn something new

  • @m.smanoj4688
    @m.smanoj4688 3 ปีที่แล้ว +2

    Awesome questions my friend 🤗.even in clg they won't teach this hidden techniques

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

    I have a very simple question.
    But before asking that I must appreciate the way you explained these super-10 questions.... Absolutely heavenly ...
    coming to my question,
    Sir may you please tell me the practical application of the static block and the instance Inisialisation block in a real world situation. An example describing both of these applications would help me a lot.

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

    Perfect series for interview preparation...👌

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

    Thanks Naveen..👍👍it's really helpful..pls continue such type of interview questions series

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

    Thanks Naveen..Its really helpfull for interview preparation.

  • @mohitchauhan4996
    @mohitchauhan4996 3 ปีที่แล้ว +1

    Thanks a lot Naveen for preparing this series.. You are superb

  • @palspal2329
    @palspal2329 3 ปีที่แล้ว +1

    Amazing explanations sir, I am really fortunate to find such great content in TH-cam.

  • @munich-germanylife8207
    @munich-germanylife8207 3 ปีที่แล้ว +1

    Overall explanation was good but I didn't find the answer for below things :
    1. If Constructor is Private and I am writting a object creation in static block how I can use it outside class
    2. Can I run the code witout Main() method, of yes I think you could have given one example in one class without main method instead of calling a second class where main method is not there
    But again sir big fan , always love your content.Please keep on doing your good works and help others to upskill there knowledge

  • @015kavya
    @015kavya 3 ปีที่แล้ว +1

    Thank you so much Naveen. It looks easy but its very tricky

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

    Okay this is the first time I heard of such things..

  • @baazishaik3578
    @baazishaik3578 3 ปีที่แล้ว +1

    Really great work sir,..ameerpet,Hyderabad mein venkatesh sir bolke ek sir hai..yeh poora bolthe thei,as per the interview's going on..aap unki yaad dilaadi hai..thank u :):)

    • @naveenautomationlabs
      @naveenautomationlabs  3 ปีที่แล้ว +1

      Thanks brother. I have never been to Ameerpet, Hyderabad. Wish one day I'll visit that place.

    • @baazishaik3578
      @baazishaik3578 3 ปีที่แล้ว +1

      @@naveenautomationlabs always welcome sir..god bless u :)

  • @m.smanoj4688
    @m.smanoj4688 3 ปีที่แล้ว +2

    Pls continue this type of interview questions

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

    Hi Naveen, i am curious to understand where exactly a static block can be used in a framework design and how it will serve the purpose. Also a request when you explain the concept please explain where exactly it will fit in framework. It will help us to create better framework.

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

    Awesome explanation! these could be quite tricky even for some experienced programmers.

  • @padminib.v.8509
    @padminib.v.8509 3 ปีที่แล้ว +1

    Thank you very much Naveen sir for these series.. Really helping a lot 😊

  • @varshamishra8743
    @varshamishra8743 3 ปีที่แล้ว +1

    VERY HELPFUL THANK YOU SIR

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

    Naveen, a great series. One doubt. In question 4, the question is to run a Java program without main() method. You have created a class without main method but called that class from another main method only, isn't it?

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

      After watching the video, the same question came to my mind right away. so, I tried to check the comments to find the answer but still couldn't if you have the answer or Naveen knows the answer please kindly share it

  • @harshshiyani2058
    @harshshiyani2058 3 ปีที่แล้ว +1

    🔥🔥🔥🔥
    Thank you sir...
    Stay safe and keep making these type of videos....

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

    Thank you sir for such amazing explanation 🙏

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

    Hi Naveen, Thanks for such helpful videos. I have started my career as a manual tester n now moved to automation by watching your videos.
    One question: how to take a screenshot of full page is one go(e.g there is one page where we need to scroll, wo how to take single screenshot of that page)?

  • @vinith2320
    @vinith2320 3 ปีที่แล้ว +1

    Naveen I can't thank you enough👍
    Keep creating more and more
    your daily videos motivates me to learn further more
    Naveen ,one more thing recently I came through a string question and I tried to do it on my own
    but Expected output is not coming I'll paste question here do give me a solution Naveen if you Know
    QUESTION :
    " Welcome to Java and Python "
    Replace first 2 letters of each word in given string with number 12
    EXPECTED OUTPUT:
    " 1212lcome 1212 1212va 1212d 1212thon "

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

      Just use Stringtokenizer.. Tokenize the string with default constructor and u will get each words thn change the first two characters to 12

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

    You are a perfect teacher great work!

  • @k.ravichandra1049
    @k.ravichandra1049 2 ปีที่แล้ว

    Thanks a ton NAVEEN for covering Static and Instance related questions which are very useful. Keep up the Good 👍 work. Also in video Q5 is without using main() method but explained using main() method pls check once.or did I miss anything pls clarify

  • @poojashaw8526
    @poojashaw8526 3 ปีที่แล้ว +1

    Very helpful video. Thank you so much 🙏🏻

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

    Nice one. Please create similar complex type interview questions on collection framework.

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

    I am regularly follow your videos. It's awesome explanation. I have a doubt, in this video at 11.01, you are still using main method. Please explain this.

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

    Great collection brother

  • @divyalakshmi4793
    @divyalakshmi4793 3 ปีที่แล้ว +1

    Thank you so much..

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

    Very helpful..plz continue with such videos

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

    Nice explaination ,, Thanks 👍👍

  • @bollywood90ssongs65
    @bollywood90ssongs65 3 ปีที่แล้ว +1

    11:49- the question is run program without writing main method but you executed program inside the main method by creating object.

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

    Very helpful

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

    nice explanation Naveenji ,but I have a doubt though we are creating object in static method, still we are using same private constructor, so logically it should not create object ri8? ..is it like we are creating object in somewhere other than heap memory?. Expecting your reply. Thank you!

  • @nishikantwairkar6866
    @nishikantwairkar6866 3 ปีที่แล้ว +2

    Thank u guru

  • @vidyabathija9112
    @vidyabathija9112 3 ปีที่แล้ว +1

    It's very helpful thank you :)

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

    In general also we execute programs by not creating any object(in the code)
    we write
    class{
    public static void main(){
    }
    }...
    it will work without creating any object right

  • @VineetKumar-eb3lv
    @VineetKumar-eb3lv 3 ปีที่แล้ว +1

    Thank you Naveen

  • @Anastasia-bo1uc
    @Anastasia-bo1uc 3 ปีที่แล้ว +1

    Thank you! Great explanation! ❤

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

    Nice video,Please share interview questions on multithreading

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

    Naveen just one question if we can create instance for class which has private constructor inside static block/method then how can we achieve singleTon class or Object ? as SingleTon Object was meant for not to allow to create more than one instance by making constructor as private ?

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

    Hi Naveen sir , you created object of static block class in main method. #regarding complile n run without main method questions. Only one main method is needed in java project. Could you please clear my doubt

  • @-Shivaprasad-qg5qj
    @-Shivaprasad-qg5qj ปีที่แล้ว

    You are awesome.... Sir

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

    naveen can u discuss testing mobile interview question and especially Appium automation

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

      Sure I'll prepare one series on appium Interview questions

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

      I have interview next Tuesday, i hope that u can send me some questions so i can prepare

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

    Very useful content...great Naveen!!

  • @sreereshvkm726
    @sreereshvkm726 3 ปีที่แล้ว +1

    Thanks Naveen.Great initiative. Keep going.❤️❤️

  • @naveenmekala3604
    @naveenmekala3604 9 หลายเดือนก่อน

    Great video Naveen 👍👍👍

  • @ChrisAthanas
    @ChrisAthanas 3 ปีที่แล้ว +1

    This is great

  • @archanagupta2862
    @archanagupta2862 3 ปีที่แล้ว +2

    please give any real time scenario where we can use it in our script .

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

    Hello, I have a quick doubt: Technically, aren't we creating String objects and interning them (because we used literals) in the second question? I understand, you not calling any of the classes you defined before but String are created, right? Thanks for the video.

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

    The java compiler copies the instance initializer block in the constructor after the first statement super(). So firstly, constructor is invoked.

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

    Love your work. Keep making videos❤️

  • @shankardayal6928
    @shankardayal6928 3 ปีที่แล้ว +2

    Thanks @Naveen sir for this series

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

    Amazing 🤩

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

    Naveen sir, how can we utilize the obj created in the static block , in another class?

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

    In question 6 how can an instance variable can access in static block whereas static block accepts only static variables or method, Can u explain brother..?

  • @sagarmane2658
    @sagarmane2658 3 ปีที่แล้ว +1

    How to access the object created in static block in another class?

  • @sivaramapandian3923
    @sivaramapandian3923 3 ปีที่แล้ว +1

    u nailed it 🔥

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

      Thank you Shiva

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

      @@naveenautomationlabs kindly start the series of algorithm like backtracking greedy such on

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

    one doubt in the time interval 11:51 and 14:24 same kind of code is present for static variable and blocks then how the static block in 11:51 alone execute?

  • @vikasyadav-es8uh
    @vikasyadav-es8uh 3 ปีที่แล้ว +1

    Output will be :-
    First static block will execute at the time of class loading then main method execute
    :- static block
    :- main method
    Non static block will not execute becouse at the time of object creation constructor will be called and befor executing constructor non static block will execute so in this case we are not creating object so no instance block no constructor..... M i right

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

    For Q.8 in the output questions in the second part of video, if I remove the final keyword from variable, even if the static keyword is present the static block is getting executed. Why is that? including the final keyword does not loads the class?

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

    If we are creating an object of the class in the static block , how do we access it from another class?

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

    at 16:50>> answer will be static block and main, because object is not created so instance block will not be executed.

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

    Hi sir,
    Why non static block execute before constructor?

  • @deeptisharma9154
    @deeptisharma9154 5 หลายเดือนก่อน

    sir in q5 we cant do anything in java if main method is not written...........

  • @Ellenki_007
    @Ellenki_007 3 ปีที่แล้ว +1

    is the relationship between Java and HTML, CSS, python, XML please show me a program that is made with all these?

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

      its a wrong question. You are comparing orange with apple here. You dont write java code with python. Also what does it mean relationship between java, python, xml, css and html?

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

    Hey Naveen can we call static method inside static block???

    • @naveenautomationlabs
      @naveenautomationlabs  3 ปีที่แล้ว +1

      Yes, you can.
      static {
      System.out.println("hi");
      test();
      }
      public static void test() {
      }

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

      One more confusion I have......
      Can we call non static mathod in static block.....
      I tried to refer some site but it is showing results for .... I can't call non static method in static method......
      But my question is can we call non static method in static block..

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

    4th question is Singleton class?

  • @Ellenki_007
    @Ellenki_007 3 ปีที่แล้ว +1

    what's the package Java practices doing in that programs

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

      why? how does it matter? its a package name where class is present.

  • @Tidda420
    @Tidda420 3 ปีที่แล้ว +1

    Bhagwan aapko ek din Tesla ka CEO banaye .jinke sirf tweet karne se shares ke price badh jaate hai .

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

    Hey Naveen, In Q10 You said Constructor of the class will not be called if you will not create the object of the class @17:18
    In your POM Framework video [(th-cam.com/video/LxJzeiTQGoE/w-d-xo.html); @58:40]. You created a LoginPageTest Constructor to call parent class constructor so that config.properties file can be loaded.
    Now My Question is We have not created any object of LoginPageTest but still constructor of LoginPageTest is called, why ?
    If you try this inside psvm(String[] args) then the constructor will not be called, But in TestNG Constructor is being called even without creating Object. Can you or anyone explain this.

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

    Please provide your telegram link updated

  • @debasreetenyson5386
    @debasreetenyson5386 3 ปีที่แล้ว +1

    Disliking this video is a crime.

  • @X_Potato
    @X_Potato 3 ปีที่แล้ว +1

    About Question 2 , Isn't "System" an object ?

    • @naveenautomationlabs
      @naveenautomationlabs  3 ปีที่แล้ว +1

      System is a class in Java, not an Object.

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

      @@naveenautomationlabs ah i see, I'm learning java and your videos are a huge help, thank you for the reply.

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

    please subtitle