Interview Questions: Etiam Sit Amet Est
Interview Questions: Etiam Sit Amet Est
Interview Questions: Etiam Sit Amet Est
C O R E JAVA ( T H E O RY )
INTERVIEW QUESTIONS
BY- RAHUL C HAUHAN
T O P I C - 1. JAVA B A S I C S
6. What is JDK?
9. Write down the minimal tools required for creating the first java application?
11. How many methods we have in java to print something on the console?
www.incapp.in
PAGE 2 OF 29
20. Write down all non-primitive DataTypes?
25. What are Uniary, Binary, and Ternary Operators? Explain with syntax.
26. Is it possible to use increment operators with data directly? Ex. 3++;
27. Is it possible to use ++ or -- operator with character and floating-point data variables?
39. What are the allowed data types in switch condition and switch cases?
www.incapp.in
PAGE 3 OF 29
41. What are the types of the loop?
45. What is a labeled and unlabeled loop? Explain with the program.
46. Write a program that explains the need for "for-loop" and "while-loop"?
49. What is the difference between double and float variables in Java?
www.incapp.in
PAGE 4 OF 29
TOPIC-2. OOP BASICS
10. Can we have same method name and same variable name in a class?
12. What’s the difference between comparison done by equals method and == operator?
www.incapp.in
PAGE 5 OF 29
TOPIC-3. STATIC KEYWORD
1. What is static-initializer?
5. When exactly the static variable and non-static variable (instance variable) got memory
allocation?
6. If we are having two variable (static x & non-static y) in class and creating 5 instances of
that class. Then tell how many times x and y variable created in memory?
7. Is it possible to directly access the non-static member inside the static initializer of the
same class?
8. Is it possible to directly access the non-static member inside the static method of the
same class?
9. Write a program to access the non-static member of a class inside the static method of
the same class.
10. Is it possible to overload two static methods? If yes then write a program.
11. Is it possible to declare more than one static initializer in a class? If yes then write a
program and output.
www.incapp.in
PAGE 6 OF 29
TOPIC-4. CONSTRUCTOR
1. What is Constructor?
5. Is it possible to have a different name of the contractor than the class name?
18. It is possible to directly access the static-member inside, the constructor of the same
class?
www.incapp.in
PAGE 7 OF 29
19. Is it possible to declare more than one initialize block in a class? If yes then write a
program and output.
20. What is a singleton class? Explain with practical example and use.
21. Is it possible to write more than one constructor chaining statement in a constructor?
22. Can we call the constructor of a class more than once for an object?
www.incapp.in
PAGE 8 OF 29
TOPIC-5. INHERITANCE
1. What is Inheritance?
4. Does the instance/object of the sub-class contain the memory of the private-member of
the super-class?
5. Is it possible to access the private member of the super-class inside the sub-class?
6. Is it possible to call the constructor of super-class inside the sub-class without creating a
separate object of super-class?
8. Name the class, which is the default super-class of every java class.
10. Is it possible to inherit a class that has only one constructor which is private?
11. Is it possible to inherit a class that has only one constructor that is protected?
14. Is it possible to use "this." and "super." Inside the static context of a class?
16. What type of inheritance is not supported in java classes and why?
www.incapp.in
PAGE 9 OF 29
19. Can a class be a super-class and a sub-class at the same time? Give example.
www.incapp.in
PAGE 10 OF 29
T O P I C - 6 . P O LY M O R P H I S M
www.incapp.in
P A G E 11 O F 2 9
20. Write a program for runtime polymorphism?
21. Is it possible to achieve compile-time polymorphism with inheritance? If yes, then write
a program.
37. Is it possible to hold the object of super-class in the reference of the sub-class?
38. Is it possible to hold the object of the sub-class in the reference of the super-class?
39. Is it possible to access the member of the super-class from the reference of the sub-
class?
www.incapp.in
PA G E 12 O F 2 9
40. Is it possible to access the member of the sub-class from the reference of the super-
class?
51. Is it possible to declare a static method and a static variable in abstract class?
52. Is it possible to declare a static method and a static variable in the interface?
57. Is it compulsory to use abstract keyword to declare abstract method in the interface?
www.incapp.in
PAG E 13 O F 2 9
61. Can we declare a class as Abstract without having any abstract method in it?
64. When you are inheriting a class and an interface than is it true, that class inheritance
must come first?
www.incapp.in
PAG E 14 O F 2 9
T O P I C - 7. F I N A L K E Y W O R D
9. Is it possible to declare a non-static final variable and initialize it from the static block?
10. Is it possible to declare a static final variable and initialize it from the constructor?
11. Is it possible to declare a static final variable and initialize it from the static block?
12. Is it possible to declare a non-static final variable and initialize it from the constructor?
www.incapp.in
PAG E 15 O F 2 9
TOPIC-8. NESTED CLASS
3. Write the signature of creating the object of non-static (inner) nested class from outside
the outer/upper class?
4. Write the signature of creating the object of static Nested Class from outside/upper
class?
6. Is it possible to access the private data of the outer class inside the inner class directly?
7. Is it possible to access the non-static private data of the outer class inside the static
nested class directly?
8. Is it possible to access the non-private member of the inner class from the reference of
the outer class?
9. Is it possible to access the non-private member of the outer class from the reference of
the inner class?
10. Is it possible to declare the static variable in the inner class? If yes, then write a
program.
11. Is it possible to declare a static method and static initializer inside the inner class?
12. Is it possible to declare the static method and static initialize inside the inner class?
13. Is it possible to declare the static initializer inside the static nested class?
14. Is it possible to access a local nested class from outside that local block?
15. Is it possible to access the private data of the outer class inside the local nested class?
www.incapp.in
PAG E 16 O F 2 9
16. What is an anonymous nested class?
18. Is it possible to declare a non-overridden method inside the anonymous nested class?
20. Write the signature of creating the object of anonymous nested class?
22. How many classes the following program contains? Write the byte-code names of all
classes:
class A{
class B{ }
void m(){
class C{ }
class B{ }
A(){
class B{ }
class E{ }
B b=new B(){ };
B b2=new B();
B b=new B(){ };
www.incapp.in
PA G E 17 O F 2 9
TOPIC-9. PAC KAGES
6. Is it possible to access the default member of a public class outside the package?
7. Is it possible to access the public member of the default class outside the package? If
yes, then write the program.
10. Write the compilation command that creates the byte-code and package folder also?
12. There are two classes named A and B. Both classes are in the same package. Can a
private member of A can be accessed by an object of B?
15. Is it possible to have multiple public classes in a single java source file?
www.incapp.in
PAG E 18 O F 2 9
TOPIC-10. EXCEPTION HANDLIN G
1. What is Exception?
9. Is it possible to write more than one catch block with a try block?
10. Is it possible to write more than one finally block with a try block?
11. Is it possible to declare the final variable inside try or catch or finally block?
12. What happens, when there is a try-catch block but it does not contain any exception
throwing statement?
www.incapp.in
PAG E 19 O F 2 9
19. What is exception propagation?
www.incapp.in
PAGE 20 OF 29
T O P I C - 11 . A R R A Y S
1. What is an Array?
4. What type of loop control designed specialty for array & collections?
I. Integer a[ ]={2,6,5};
www.incapp.in
PAG E 21 O F 2 9
VI. double a[]={2,6.1,5.0};
14. Write a program to print the sum of all the elements of an int type array?
15. Write a program to print maximum value element of an int type array?
VII. System.out.println(a[0]);
VIII. System.out.println(a[0][1]);
19. Write the program to print both the diagonal of a 2-D int type Array?
20. Name the method that sort the array elements in one go?
www.incapp.in
PAGE 22 OF 29
T O P I C - 12 . S T R I N G
2. What is the name of the package that contains the String class?
4. When we create a string class object, internally a char type array created or not?
String s= “Hello”;
s= s+ “Hi” +5;
String s= “hello”;
s=s.concat(“Hi”).concat(5);
11. How many String Objects are created in the following code?
www.incapp.in
PAGE 23 OF 29
String s3="Java Language";
12. When lots of changes are required in string data, which one class should be used? String
or StringBuffer?
www.incapp.in
PAGE 2 4 OF 29
T O P I C - 13 . W R A P P E R C L A S S
Integer.parseInt()
Integer.valueOf()
Integer.decode()
System.out.println(a==b);
System.out.println(x==y);
System.out.println(p==q);
www.incapp.in
PAGE 25 OF 29
10. Write down the ways to convert a primitive type to a wrapper object.
11. Write down the ways to convert wrapper object to primitive type.
www.incapp.in
PAGE 26 OF 29
T O P I C - 14 . VA R - A R G S
1. What is var-args?
www.incapp.in
PAGE 27 OF 29
T O P I C - 15 . P U B L I C S TAT I C VO I D M A I N
2. What happens, when the main-method does not have "public" and "static" keyword?
8. Is it possible to compile a java program successfully without even having a main method
in it?
www.incapp.in
PAGE 28 OF 29
CONTACT DETAILS:
Email: info@incapp.in
Website: www.incapp.in
www.incapp.in
PAGE 29 OF 29