300+ [LATEST] Java Programmer Interview Questions and Answers

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, because interface fields are static and final by default and you can’t change their value once they are initialized. In the above code, methodB() is changing value of interface field A.i. It shows compile 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

3

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 local members 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 correctly. But, it will throw StackOverflowError at run time. Because, methodOne() and methodTwo() are cyclicly called.

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 correctly. Output will 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 correctly. Output will 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 errors.

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

False. Interfaces don’t extend Object class.

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 file, .class file will be generated after compilation.

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

False. Interfaces are abstract by default but not public.

Q15. Can We Define Interface As Generic?

Yes, we can define generic interface

Q16. Does Below Program Compile Successfully?

Interface Abc
{
Public Void Methodone();
Public Void Methodtwo();
}
Interface Pqr Extends Abc
{

Yes, program compiles successfully.

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

Class A Implements A.b
{

Static Interface B
{
Void Methodb();
}
}

Cycle detected. Any class can not extend itself or it’s member types.

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

Illegal modifier for field 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
{
//class A
}
Interface B Extends A
{
//interface B Extending Class A
}

No. An interface can extend another interface not 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 8, interfaces can 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, program is correct. Output will be,

3

2

1

3

2

3

3

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

Abstract Class A
{
Abstract Void Mymethod(number N);
}
Interface B
{
Abstract Void Mymethod(object

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 8, interfaces can have static methods and default methods other than abstract methods.

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 must be implemented as public. Because, interface methods are public by default and you should not reduce the visibility of any methods while overriding.

Q30. Can A Class Implement More Than One Interfaces?

Yes, a class 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 must implement methodX() also.