Here is a few questions that I find it useful for preparing the interviews (Java).
A few thing you have to know first:
- It is possible to have more than one class in a single Java file but only 1 public class is allowed.
- It is possible to have a main method in each class
1 2 3 4 5 6 7 8 9 10 | class A { public static void main(String…s) { } public static void main(int…s) { } } |
class A { public static void main(String…s) { } public static void main(int…s) { } }
Question 1: Can we invoke main method explicitly?
Answer: Of course
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class A { public static void main(String…s) { System.out.println(“Hello”); } Class B { public static void main(String…s) { A.main(); } } } |
class A { public static void main(String…s) { System.out.println(“Hello”); } Class B { public static void main(String…s) { A.main(); } } }
Question 2: Can we execute the Java program without main method?
Answer: Yes
Example:
1 2 3 4 5 6 7 | class A { static { System.out.println(“HelloACM.com”); } } |
class A { static { System.out.println(“HelloACM.com”); } }
Question 3: What is difference between object and class?
Answer: A object is an instance of the class. The class can be considered as [skeleton] or [template] of the objects.
Question 4: Why character cosumes 2 bytes in java?
Answer: Java support UNICODE and for UNICODE 2 bytes are used.
Question 5: Why the [main] method is static?
Answer: Static main function is the entry of the Java application. Every object has the same entry.
Question 6: When the constructor is called?
Answer: When an object is created.
Question 7: Inheritance occurs at runtime?
Answer: Yes
Question 8: What is the purpose of using dynamic binding?
Answer: To achieve abstraction.
Question 9: Is constructor allowed in abstract class?
Answer: Yes
Question 10: Is it allowed to have a static abstract method?
Answer: No
Question 11: How to invoke the abstract class method?
Answer: The dynamic binding.
Example:
1 | base b = new child(); |
base b = new child();
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Picture Explorer, Sort Pictures by Facebook Likes
Next Post: Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM
Frequently Asked Core Java Interview Questions and Answer
I was searching for some java questions and answers, where my java queries has been resolved in very short span of time.