Test your Java Knowledge with these Tricky questions
Java is one of the famous programming languages by the majority of the software developers over the globe. Java has been used for developing complex applications in desktop, mobiles, tablets. So this is the reason behind why Java experts are in high demand in the software field and today the majority of the application developers are moving to Java language to develop their application. To win in this highly competitive race make sure you have an in-depth knowledge of Java with the advanced level. Also, it is preferable to take Java Training before entering into any programming field. Since Java is the base for all languages. Obviously, everyone knows the basic Java interview questions, so here are some of the tricky Java interview questions.
Shall we override a private or static method in Java?
Overriding is the best topic to ask tricky questions in Java. You cannot override a private or static method because when you create the same method with same method arguments and same return type in child class then it will hide the superclass method. Like that, it is not possible to override a private or static method in Java, since it is not accessible. It is preferable to create another private method with same method name in the child class.
Why is Multiple Inheritance not supported in Java?
Java doesn’t support multiple inheritances since multiple inheritance may cause ambiguity in some situations. The e.g. scenario is Diamond problem.
Let us assume that we have a method in Class A, B and C overrides the method in their own way. Class D is extending B and C If D wants to use the same method which method could call (method B or method C). Here comes the ambiguity. This is one of the main reasons for not using the Multiple Inheritance in Java.
Why is String immutable or final in Java?
The string is immutable in Java since objects in strings are cached in the string pool. Cached strings are shared among many clients. For e.g. if one client changes the value it will affect the other clients also.
Why is Char array better than String in Java for storing password?
Since Strings are immutable, contents of the strings cannot be changed. But when you use char[] you can set the element as even zero. So when you store the password in char[] you can avoid of hacking the password.
These are my list of Java tricky questions and answers. Experienced Java professionals won’t see these questions as tough. But it is really tough for beginner level and intermediate level programmers. If you want to know more about Java take up Java Training in Chennai and also it is more important to choose the Best Java Training Institute in Chennai to learn Java programming language.
