YouTube Icon

Interview Questions.

Top 32 Java Programmer Interview Questions - Jul 26, 2022

fluid

Top 32 Java Programmer Interview Questions

Q1. What Will Be The Output Of The Below Program?

Interface X

Void Method();

Class Y

Public Void Method()

System.Out.Print

CLASS Y

Q2. Does Below Code Compile Successfully? If Not, Why?

Interface A

Int I = 111;

Class B Implements A

Void Methodb()

I = 22

No, due to the fact interface fields are static and very last by means of default and you could’t change their cost once they are initialized. In the above code, methodB() is changing price of interface subject A.I. It shows assemble time error.

Q3. What Will Be The Output Of The Following Program?

Class A  

Class B Extends A  

Class C Extends B  

Interface Abc

Void Method(a A);

2

three

3

Q4. What Will Be The Output Of The Following Program?

Interface X

Char C = 'a';

Char Methodx();

Class Y Implements X

 

A

B

A

A

Q5. Can You Identify The Error In The Below Code?

Interface A

Void Methoda();

Class B Implements A

Public Void Methoda()

Inte

Interfaces can’t be nearby contributors of a method.

Q6. Is The Following Program Written Correctly? If Yes, What Will Be The Output?

Interface Abc

Void Methodone();

Interface Pqr Extends Abc

Voi

Yes, program is written is successfully. But, it'll throw StackOverflowError at run time. Because, methodOne() and methodTwo() are cyclicly known as.

Q7. Is The Below Program Written Correctly? If Yes, What Will Be The Output?

Class A Implements B

Public Int Methodb(int I)

Return I =+ I * I;

Yes, program is written efficiently. Output may be,

4

Q8. Is The Below Program Written Correctly? If Yes, What Will Be The Output?

Interface I 

Class C

Int I;

Public C(int I)

Yes, program is written efficaciously. Output may be,

2

Q9. What Will Be The Output Of The Following Program?

Interface A

Int Methoda();

Interface B

Int Methodb();

Interface C

1110

1

-1

1

Q10. Can You Identify The Errors In The Below Code?

 

Interface I

Class C Implements I

Public Void Method(int I)

Syst

No mistakes.

Q11. Like Classes In Java, Interfaces Also Extend Java.Lang.Item Class By Default. True Or False?

False. Interfaces don’t make bigger Object elegance.

Q12. What Will Be The Output Of The Following Program?

Interface A

Void Mymethod();

Class B

Public Void My Method()

System.Out.Prin

My Method

Q13. For Every Interface Written In A Java File, .Class File Will Be Generated After Compilation? True Or False?

True. For every interface written in a java report, .Elegance document might be generated after compilation.

Q14. Interfaces Are Abstract And Public By Default. True Or False?

False. Interfaces are abstract through default but now not public.

Q15. Can We Define Interface As Generic?

Yes, we are able to define established interface

Q16. Does Below Program Compile Successfully?

Interface Abc

Public Void Methodone();

Public Void Methodtwo();

Interface Pqr Extends Abc

Yes, program compiles correctly.

Q17. Can You Identify The Error In The Below Code?

Class A Implements A.B

 

Static Interface B

Void Methodb();

 

Cycle detected. Any class cannot extend itself or it’s member kinds.

Q18. Can You Identify The Error In The Below Code? Interface A  Private Int I; 

Illegal modifier for discipline i. Only public, static and final are allowed.

Q19. All Members Of Interface Are Public By Default. True Or False?

True.

Q20. Is The Following Code Written Correctly?

Class A

//magnificence A

Interface B Extends A

//interface B Extending Class A

No. An interface can amplify every other interface no longer the class.

Q21. What Will Be The Output Of The Following Program?

Interface A

String A = "aaa";

String Methoda();

Interface B

String B = "bbb";

AAABBB

BBBAAA

DDDBBBAAA

BBBAAA

Q22. Can Interfaces Have Static Methods?

Yes, from Java eight, interfaces could have static methods

Q23. Is The Below Program Written Correctly? If Yes, What Will Be The Output?

Interface X

Void Methodx();

Interface Y

Void Method();

Yes, application is correct. Output might be,

3

2

1

three

2

three

3

Q24. What Will Be The Output Of The Following Program?

Abstract Class A

Abstract Void Mymethod(range N);

Interface B

Abstract Void Mymethod(item

Number

Object

Number

Q25. What Will Be The Output Of The Following Program?

Interface One

String S = "final";

String Methodone();

Interface Two

NOT FINALFINAL

FINAL

Q26. Can Interfaces Have Methods Other Than Abstract?

Yes, from Java eight, interfaces could have static methods and default techniques other than summary strategies.

Q27. Can Interfaces Have Constructor?

No. Interfaces can’t have constructors.

Q28. What Will Be The Output Of The Following Program?

Interface P

String P = "pppp";

String Methodp();

Interface Q Extends P

Strin

QQQQPPPP

PPPPQQQQ

Q29. Why The Below Code Is Showing Compile Time Error?

Interface X

Void Method X();

Class Y Implements X

Void Methodx()

System.Out.

Interface methods should be implemented as public. Because, interface strategies are public by means of default and you need to no longer reduce the visibility of any strategies whilst overriding.

Q30. Can A Class Implement More Than One Interfaces?

Yes, a category can implement more than one interfaces.

Q31. Can You Find Out The Errors In The Following Code?

Interface A

 

System.Out.Println("interface A");

Static

Sy

Interfaces can’t have initializers.

Q32. Can You Identify The Error In The Below Code?

Interface X

Void Methodx();

Interface Y Extends X

Void Methody();

Class Z Impleme

Class Z need to put into effect methodX() also.




CFG