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

  Рет қаралды 50,116

Naveen AutomationLabs

Naveen AutomationLabs

3 жыл бұрын

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:
kzbin.info%20Au...
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/COJqZUPB02r5sB7...
Naveen AutomationLabs Paid Courses:
Java & Selenium:
naveenautomationlabs.com/manua...
Java & API +POSTMAN + RestAssured + HttpClient:
naveenautomationlabs.com/selen...

Пікірлер: 114
@sridharlanka2721
@sridharlanka2721 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
One of my favourite teacher, who used to give concepts from scratch . 🙏🙏
@nikeshkumar-gl1fv
@nikeshkumar-gl1fv 3 жыл бұрын
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 🙏🙏🙏🙏🙏🙏🙏
@pandudamera7211
@pandudamera7211 3 жыл бұрын
Great collection brother
@samarthurs8000
@samarthurs8000 3 жыл бұрын
Awesome explanation! these could be quite tricky even for some experienced programmers.
@anneshapalchoudhary4710
@anneshapalchoudhary4710 3 жыл бұрын
You are a perfect teacher great work!
@fouqiazeba8073
@fouqiazeba8073 Жыл бұрын
Amazing 🤩
@m.smanoj4688
@m.smanoj4688 3 жыл бұрын
Awesome questions my friend 🤗.even in clg they won't teach this hidden techniques
@AdamantMindset
@AdamantMindset 2 жыл бұрын
Okay this is the first time I heard of such things..
@SumitSharma-qq4hk
@SumitSharma-qq4hk 3 жыл бұрын
Awesome.... Everytime there is a video by you, I learn something new
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Glad that you are learning from my channel 😊
@soumyanetrapal4815
@soumyanetrapal4815 2 жыл бұрын
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.
@ChrisAthanas
@ChrisAthanas 3 жыл бұрын
This is great
@niloybasu6508
@niloybasu6508 Жыл бұрын
This is really very useful..Completely cleared my doubts. Thanks a lot for making such awesome videos.
@VineetKumar-eb3lv
@VineetKumar-eb3lv 3 жыл бұрын
Thank you Naveen
@vibhanidhi
@vibhanidhi 3 жыл бұрын
Thanks Naveen..👍👍it's really helpful..pls continue such type of interview questions series
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thanks for watching :)
@gauravdewalkar4830
@gauravdewalkar4830 3 жыл бұрын
Love your work. Keep making videos❤️
@naveenmekala3604
@naveenmekala3604 7 ай бұрын
Great video Naveen 👍👍👍
@saikigaj
@saikigaj 3 жыл бұрын
Perfect series for interview preparation...👌
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thank you 😊
@namratasharma8439
@namratasharma8439 2 жыл бұрын
Thanks Naveen..Its really helpfull for interview preparation.
@monalikajain
@monalikajain 3 жыл бұрын
Very useful content...great Naveen!!
@vidyabathija9112
@vidyabathija9112 3 жыл бұрын
It's very helpful thank you :)
@deepa8177
@deepa8177 3 жыл бұрын
Very helpful..plz continue with such videos
@divyalakshmi4793
@divyalakshmi4793 3 жыл бұрын
Thank you so much..
@harshshiyani2058
@harshshiyani2058 3 жыл бұрын
🔥🔥🔥🔥 Thank you sir... Stay safe and keep making these type of videos....
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thank you harsh.
@dhineshs6210
@dhineshs6210 2 жыл бұрын
Nice explaination ,, Thanks 👍👍
@padminib.v.8509
@padminib.v.8509 3 жыл бұрын
Thank you very much Naveen sir for these series.. Really helping a lot 😊
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Glad to hear that 😀
@nishikantwairkar6866
@nishikantwairkar6866 3 жыл бұрын
Thank u guru
@-Shivaprasad-qg5qj
@-Shivaprasad-qg5qj Жыл бұрын
You are awesome.... Sir
@mohitchauhan4996
@mohitchauhan4996 3 жыл бұрын
Thanks a lot Naveen for preparing this series.. You are superb
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
It's my pleasure
@gokulm6299
@gokulm6299 3 жыл бұрын
Thank you sir for such amazing explanation 🙏
@m.smanoj4688
@m.smanoj4688 3 жыл бұрын
Pls continue this type of interview questions
@harekrishnasingh6874
@harekrishnasingh6874 3 жыл бұрын
no more confusion on static block....thank u myguru....!!!!
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Most welcome :)
@palspal2329
@palspal2329 3 жыл бұрын
Amazing explanations sir, I am really fortunate to find such great content in KZbin.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Glad to hear that
@sreereshvkm726
@sreereshvkm726 3 жыл бұрын
Thanks Naveen.Great initiative. Keep going.❤️❤️
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thanks 😊
@015kavya
@015kavya 3 жыл бұрын
Thank you so much Naveen. It looks easy but its very tricky
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Glad that you got it.
@bollywood90ssongs65
@bollywood90ssongs65 3 жыл бұрын
11:49- the question is run program without writing main method but you executed program inside the main method by creating object.
@Anastasia-bo1uc
@Anastasia-bo1uc 3 жыл бұрын
Thank you! Great explanation! ❤
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thanks for watching.
@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)?
@poojashaw8526
@poojashaw8526 3 жыл бұрын
Very helpful video. Thank you so much 🙏🏻
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thanks for watching pooja. Hope you are doing well.
@varshamishra8743
@varshamishra8743 2 жыл бұрын
VERY HELPFUL THANK YOU SIR
@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.
@bikashkonar8930
@bikashkonar8930 2 жыл бұрын
Nice one. Please create similar complex type interview questions on collection framework.
@nitzcookinglove2477
@nitzcookinglove2477 3 жыл бұрын
Very helpful
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Glad to hear that
@nishujoshi508
@nishujoshi508 3 жыл бұрын
Nice video,Please share interview questions on multithreading
@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
@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.
@baazishaik3578
@baazishaik3578 3 жыл бұрын
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 жыл бұрын
Thanks brother. I have never been to Ameerpet, Hyderabad. Wish one day I'll visit that place.
@baazishaik3578
@baazishaik3578 3 жыл бұрын
@@naveenautomationlabs always welcome sir..god bless u :)
@munich-germanylife8207
@munich-germanylife8207 3 жыл бұрын
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
@archanagupta2862
@archanagupta2862 3 жыл бұрын
please give any real time scenario where we can use it in our script .
@sivaramapandian3923
@sivaramapandian3923 3 жыл бұрын
u nailed it 🔥
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thank you Shiva
@sivaramapandian3923
@sivaramapandian3923 3 жыл бұрын
@@naveenautomationlabs kindly start the series of algorithm like backtracking greedy such on
@ahamedabdulrahman
@ahamedabdulrahman 3 жыл бұрын
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
@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
@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
@vinith2320
@vinith2320 3 жыл бұрын
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
@prajaktatotre8138
@prajaktatotre8138 3 жыл бұрын
The java compiler copies the instance initializer block in the constructor after the first statement super(). So firstly, constructor is invoked.
@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 ?
@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!
@sssaamm29988
@sssaamm29988 2 жыл бұрын
Naveen sir, how can we utilize the obj created in the static block , in another class?
@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?
@shankardayal6928
@shankardayal6928 3 жыл бұрын
Thanks @Naveen sir for this series
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Glad to hear that
@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.
@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?
@alaaali9745
@alaaali9745 3 жыл бұрын
naveen can u discuss testing mobile interview question and especially Appium automation
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
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
@sagarmane2658
@sagarmane2658 3 жыл бұрын
How to access the object created in 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..?
@sonuraviraj8754
@sonuraviraj8754 3 жыл бұрын
Hi sir, Why non static block execute before constructor?
@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 11 ай бұрын
at 16:50>> answer will be static block and main, because object is not created so instance block will not be executed.
@deeptisharma9154
@deeptisharma9154 3 ай бұрын
sir in q5 we cant do anything in java if main method is not written...........
@Ellenki_007
@Ellenki_007 3 жыл бұрын
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?
@Ellenki_007
@Ellenki_007 3 жыл бұрын
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.
@sruthibhagavatula2450
@sruthibhagavatula2450 3 жыл бұрын
4th question is Singleton class?
@Tidda420
@Tidda420 3 жыл бұрын
Bhagwan aapko ek din Tesla ka CEO banaye .jinke sirf tweet karne se shares ke price badh jaate hai .
@amrutajadhav8455
@amrutajadhav8455 3 жыл бұрын
Hey Naveen can we call static method inside static block???
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
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..
@vikasyadav-es8uh
@vikasyadav-es8uh 3 жыл бұрын
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
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Yup right.
@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 [(kzbin.info/www/bejne/gqmtq5ifibZ6pac); @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
@MalalaValala
@MalalaValala Жыл бұрын
please subtitle
@X_Potato
@X_Potato 3 жыл бұрын
About Question 2 , Isn't "System" an object ?
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
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.
@debasreetenyson5386
@debasreetenyson5386 2 жыл бұрын
Disliking this video is a crime.
Идеально повторил? Хотите вторую часть?
00:13
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 12 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
Difference between Interface and Absract Class
30:52
Naveen AutomationLabs
Рет қаралды 179 М.
Top 25 Microservice Interview Questions Answered - Java Brains
39:54
Can we override a static method in child class? || Famous Interview Question
14:46
#15 - Top 20 HashMap Interview Questions in Java || By Naveen AutomationLabs
27:35
What is Encapsulation in Java - OOP Concept
19:44
Naveen AutomationLabs
Рет қаралды 71 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 64 МЛН
Как удвоить напряжение? #электроника #умножитель
1:00
Hi Dev! – Электроника
Рет қаралды 1,1 МЛН
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 736 М.
My iPhone 15 pro max 😱🫣😂
0:21
Nadir Show
Рет қаралды 1,9 МЛН