Java Programmer Interview Questions And Answers
Question: 1. For Every Interface Written In A Java File, .Class File Will Be Generated After Compilation? True Or False?
Answer:
True. For every interface written in a java record, .Class report can be generated after compilation.
Question: 2. Can You Identify The Error In The Below Code? Interface A Private Int I;
Answer:
Illegal modifier for field i. Only public, static and final are allowed.
J2EE Interview Questions
Question: three. What Will Be The Output Of The Following Program?
Interface A
Void Mymethod();
Class B
Public Void My Method()
System.Out.Println(“my Method”);
Class C Extends B Implements A
Class Main Class
Public Static Void Main(string[] Args)
A A = New C();
A.Mymethod();
Answer:
My Method
Question: four. Can A Class Implement More Than One Interfaces?
Answer:
Yes, a category can enforce multiple interfaces.
J2EE Tutorial
Question: five. Why The Below Code Is Showing Compile Time Error?
Interface X
Void Method X();
Class Y Implements X
Void Methodx()
System.Out.Println(“technique X”);
Answer:
Interface methods must be carried out as public. Because, interface strategies are public by means of default and also you must not lessen the visibility of any methods while overriding.
Core Java Interview Questions
Question: 6. Does Below Code Compile Successfully? If Not, Why?
Interface A
Int I = 111;
Class B Implements A
Void Methodb()
I = 222;
Answer:
No, because interface fields are static and final by using default and you could’t change their cost as soon as they’re initialized. In the above code, methodB() is converting fee of interface area A.I. It suggests compile time mistakes.
Question: 7. Is The Following Code Written Correctly?
Class A
//class A
Interface B Extends A
//interface B Extending Class A
Answer:
No. An interface can extend some other interface not the class.
Core Java Tutorial C Interview Questions
Question: eight. What Will Be The Output Of The Following Program?
Interface P
String P = “pppp”;
String Methodp();
Interface Q Extends P
String Q = “qqqq”;
String Methodq();
Class R Implements P, Q
Public String Methodp()
Return Q+p;
Public String Methodq()
Return P+q;
Public Class Mainclass
Public Static Void Main(string[] Args)
R R = New R();
System.Out.Println(r.Methodp());
System.Out.Println(r.Methodq());
Answer:
QQQQPPPP
PPPPQQQQ
Question: nine. Can Interfaces Have Constructor?
Answer:
No. Interfaces can’t have constructors.
AJAX Interview Questions
Question: 10. 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;
Interface B
Int Methodb(int I);
Public Class Mainclass
Public Static Void Main(string[] Args)
B B = New A();
System.Out.Println(b.Methodb(2));
Answer:
Yes, application is written efficaciously. Output may be,
four
C Tutorial
Question: 11. Can You Find Out The Errors In The Following Code?
Interface A
System.Out.Println(“interface A”);
Static
System.Out.Println(“interface A”);
Answer:
Interfaces can’t have initializers.
JSP Interview Questions
Question: 12. How Do You Access Interface Field ‘i’ In The Below Code?
Class P
Interface Q
Int I = 111;
Answer:
P.Q.I
J2EE Interview Questions
Question: 13. Like Classes In Java, Interfaces Also Extend Java.Lang.Item Class By Default. True Or False?
Answer:
False. Interfaces don’t increase Object magnificence.
AJAX Tutorial
Question: 14. Does Below Program Compile Successfully?
Interface Abc
Public Void Methodone();
Public Void Methodtwo();
Interface Pqr Extends Abc
Public Void Methodone();
Public Void Methodtwo();
Answer:
Yes, application compiles successfully.
Question: 15. Can Interfaces Have Static Methods?
Answer:
Yes, from Java eight, interfaces will have static methods
Java Struts Interview Questions
Question: sixteen. Is The Following Program Written Correctly? If Yes, What Will Be The Output?
Interface Abc
Void Methodone();
Interface Pqr Extends Abc
Void Methodtwo();
Abstract Class Xyz Implements Pqr
Public Void Methodone()
Methodtwo();
Class Mno Extends Xyz
Public Void Methodtwo()
Methodone();
Public Class Mainclass
Public Static Void Main(string[] Args)
Abc Abc = New Mno();
Abc.Methodone();
Answer:
Yes, software is written is effectively. But, it’ll throw StackOverflowError at run time. Because, methodOne() and methodTwo() are cyclicly known as.
JSP Tutorial
Question: 17. What Will Be The Output Of The Following Program?
Interface X
Char C = ‘a’;
Char Methodx();
Class Y Implements X
System.Out.Println(c);
Public Char Methodx()
Char C = This.C;
Return ++c;
Public Class Mainclass
Public Static Void Main(string[] Args)
Y Y = New Y();
System.Out.Println(y.Methodx());
System.Out.Println(y.C);
System.Out.Println(x.C);
Answer:
A
B
A
A
Java Servlets Interview Questions
Question: 18. Can You Identify The Error In The Below Code?
Interface A
Void Methoda();
Class B Implements A
Public Void Methoda()
Interface C
Int I = 123;
Answer:
Interfaces can’t be nearby participants of a way.
Core Java Interview Questions
Question: 19. Can We Declare An Interface As ‘summary’?
Answer:
Yes, interfaces may be declared as ‘abstract’. But, there is no want to claim like that due to the fact interfaces are ‘abstract’ by way of default.
Java Servlets Tutorial
Question: 20. What Will Be The Output Of The Following Program?
Interface One
String S = “very last”;
String Methodone();
Interface Two
String Methodone();
Abstract Class Three
String S = “now not Final”;
Public Abstract String Methodone();
Class Four Extends Three Implements One, Two
Public String Methodone()
String S = Super.S + One.S;
Return S;
Public Class Mainclass
Public Static Void Main(string[] Args)
Four Four = New Four();
System.Out.Println(four.Methodone());
One One = Four;
System.Out.Println(one.S);
Answer:
NOT FINALFINAL
FINAL
Hibernate Interview Questions
Question: 21. What Will Be The Output Of The Below Program?
Interface X
Void Method();
Class Y
Public Void Method()
System.Out.Println(“magnificence Y”);
Class Z Extends Y Implements X
Public Class Mainclass
Public Static Void Main(string[] Args)
X X = New Z();
X.Approach();
Answer:
CLASS Y
Question: 22. Can Interfaces Have Methods Other Than Abstract?
Answer:
Yes, from Java 8, interfaces can have static techniques and default strategies apart from abstract strategies.
Hibernate Tutorial
Question: 23. What Will Be The Output Of The Following Program?
Interface A
Int Methoda();
Interface B
Int Methodb();
Interface C
Int Methodc();
Class D Implements A, B, C
Int I = 999+111;
Public Int Methoda()
I =+ I / I;
Return I;
Public Int Methodb()
I =- I * I;
Return I;
Public Int Methodc()
I = ++i – –i;
Return I;
Public Class Mainclass
Public Static Void Main(string[] Args)
D D = New D();
System.Out.Println(d.I);
System.Out.Println(d.Methoda());
System.Out.Println(d.Methodb());
System.Out.Println(d.Methodc());
Answer:
1110
1
-1
1
JSTL(JSP Standard Tag Library) Interview Questions
Question: 24. How Do You Print The Value Of Field ‘i’ Of Interface ‘onetwothree’ In The Below Example And What Will Be The It’s Value?
Interface One
Int I = 222;
Interface Onetwo
Int I = One.I+one.I;
Interface Onetwothree
Int I = Onetwo.I + Onetwo.I;
Answer:
Printing ‘i’ price —> System.Out.Println(One.OneTwo.OneTwoThree.I)
Value of One.OneTwo.OneTwoThree.I might be 888.
C Interview Questions
Question: 25. All Members Of Interface Are Public By Default. True Or False?
Answer:
True.
Java Tutorial
Question: 26. What Will Be The Output Of The Following Program?
Interface A
String A = “aaa”;
String Methoda();
Interface B
String B = “bbb”;
String Methodb();
Class C Implements A, B
Public String Methoda()
Return A+b;
Public String Methodb()
Return B+a;
Class D Extends C Implements A, B
String D = “ddd”;
Public String Methoda()
Return D+methodb();
Public Class Mainclass
Public Static Void Main(string[] Args)
C C = New C();
System.Out.Println(c.Methoda());
System.Out.Println(c.Methodb());
C = New D();
System.Out.Println(c.Methoda());
System.Out.Println(c.Methodb());
Answer:
AAABBB
BBBAAA
DDDBBBAAA
BBBAAA
Java Interview Questions
Question: 27. Is The Below Program Written Correctly? If Yes, What Will Be The Output?
Interface X
Void Methodx();
Interface Y
Void Method();
Class Z Implements X, X.Y
Method();
System.Out.Println(1);
Public Void Methodx()
Methody();
System.Out.Println(2);
Public Void Methody()
System.Out.Println(3);
Public Class Mainclass
Public Static Void Main(string[] Args)
Z Z = New Z();
Z.Methodx();
Z.Methody();
X X = Z;
X.Methodx();
Answer:
Yes, application is accurate. Output may be,
3
2
1
three
2
three
3
AJAX Interview Questions
Question: 28. Can You Identify The Error In The Below Code?
Class A Implements A.B
Static Interface B
Void Methodb();
Answer:
Cycle detected. Any elegance can’t amplify itself or it’s member types.
NHibernate Tutorial
Question: 29. Interfaces Are Abstract And Public By Default. True Or False?
Answer:
False. Interfaces are summary by means of default but no longer public.
NHibernate Interview Questions
Question: 30. Can You Identify The Error In The Below Code?
Interface X
Void Methodx();
Interface Y Extends X
Void Methody();
Class Z Implements Y
Public Void Methody()
System.Out.Println(“technique Y”);
Answer:
Class Z have to implement methodX() also.
Question: 31. Can We Define Interface As Generic?
Answer:
Yes, we can define generic interface
Apache Struts 2 Tutorial
Question: 32. What Will Be The Output Of The Following Program?
Abstract Class A
Abstract Void Mymethod(wide variety N);
Interface B
Abstract Void Mymethod(object O);
Class C Extends A Implements B
Void Mymethod(range N)
System.Out.Println(“wide variety”);
Public Void Mymethod(item O)
System.Out.Println(“object”);
Public Class Mainclass
Public Static Void Main(string[] Args)
A A = New C();
A.Mymethod(new Integer(121));
B B = New C();
B.Mymethod(new Integer(121));
C C = New C();
C.Mymethod(new Integer(121));
Answer:
Number
Object
Number
Apache Struts 2 Interview Questions
Question: 33. Is The Below Program Written Correctly? If Yes, What Will Be The Output?
Interface I
Class C
Int I;
Public C(int I)
This.I = ++i;
Int Methodc()
Return ++i;
Public Class Mainclass
Public Static Void Main(string[] Args)
I.C C = New I.C(000);
System.Out.Println(c.Approach());
Answer:
Yes, software is written successfully. Output may be,
2
JSP Interview Questions
Question: 34. 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);
Interface Pqr
Void Method(b B);
Class M Implements Abc, Pqr
Public Void Method(a A)
System.Out.Println(2);
Public Void Method(b B)
System.Out.Println(3);
Public Class Mainclass
Public Static Void Main(string[] Args)
M M = New M();
M.Approach(new A());
M.Approach(new B());
M.Technique(new C());
Answer:
2
3
three
Question: 35. Can You Identify The Errors In The Below Code?
Interface I
Class C Implements I
Public Void Method(int I)
System.Out.Println(i);
Void Method(int I);
Answer:
No mistakes.