Java Question 2
Java Question 2
2. What is an object?
3. What is the difference between an object-oriented programming language and
object-based programming language?
4. What will be the initial value of an object reference which is defined as an
instance variable?
5. What is aggregation?
6. What is composition?
7. What is the difference between aggregation and composition?
Method Overloading
1. What is method overloading?
2. Why is method overloading not possible by changing the return type in java?
3. Can we overload the methods by making them static?
4. Can we overload the main() method?
5. What is method overloading with type promotion?
Constructors
1. What is the constructor?
2. How many types of constructors are used in Java?
3. What is the purpose of a default constructor?
4. Does constructor return any value?
5. Is constructor inherited?
6. Can you make a constructor final?
7. Can we overload the constructors?
8. What do you understand by copy constructor in Java?
9. What are the differences between the constructors and methods?
Static keyword
1. What is the static variable?
2. What is the static method?
3. What are the restrictions that are applied to the Java static methods?
4. Why is the main method static?
5. Can we override the static methods?
6. What is the static block?
7. Can we execute a program without main() method?
8. What if the static modifier is removed from the signature of the main method?
9. What is the difference between static (class) method and instance method?
10. Can we make constructors static?
11. Can we make the abstract methods static in Java?
12. Can we declare the static variables and methods in an abstract class?
Inheritance:
1. What is this keyword in java?
2. What are the main uses of this keyword?
3. Can we assign the reference to this variable?
4. Can this keyword be used to refer static members?
5. How can constructor chaining be done using this( )?
6. What is the Inheritance?
7. Why is Inheritance used in Java?
8. Which class is the superclass for all the classes?
9. Why is multiple inheritance not supported in java?
10. What is super in java?
11. How can constructor chaining be done by using the super()?
12. What are the main uses of the super keyword?
13. What are the differences between this and super keyword?
14. Can you use this() and super() both in a constructor?
15. What is object cloning?
Method-Overriding
1. What is method overriding:
2. Can we override the static method?
3. Why can we not override static method?
4. Can we override the overloaded method?
5. Difference between method Overloading and Overriding.
6. Can we override the private methods?
7. Can we change the scope of the overridden method in the subclass?
8. Can we modify the throws clause of the superclass method while overriding it in
the subclass?
9. Can you have virtual functions in Java?
final keyword
1. What is the final variable?
2. What is the final method?
3. What is the final class?
4. What is the final blank variable?
5. Can we initialize the final blank variable?
6. Can you declare the main method as final?
7. Can we declare a constructor as final?
8. Can we declare an interface as final?
9. What is the difference between the final method and abstract method?
Poly-Morphism
1. What is the difference between compile-time polymorphism and runtime
polymorphism?
2. What is Runtime Polymorphism?
3. Can you achieve Runtime Polymorphism by data members?
4. What is the difference between static binding and dynamic binding?
5. What is Java instanceOf operator?
Abstraction
1. What is the abstraction?
2. What is the abstract class?
3. Can there be an abstract method without an abstract class?
4. Can you use abstract and final both with a method?
5. Is it possible to instantiate the abstract class?
6. What is the interface?
7. Can you declare an interface method static?
8. Can the Interface be final?
9. What is a marker interface?
10. What are the differences between abstract class and interface?
11. Can we define private and protected modifiers for the members in
interfaces?
12. When can an object reference be cast to an interface reference?
13. Can we make abstract class final?
14. Can we create constructor for abstract class?
15. How to invoke abstract class constructors?
16. Can we overload-abstract methods?
17. Can we Override abstract methods?
18. Can we achieve multiple inheritance using java?
19. Will abstract class inherit Object class?
20. How to achieve abstraction?
21. What is the outcome of abstraction
Encapsulation
1. What is Encapsulation?
2. How to achieve encapsulation?
3. Explain java-bean class?
4. Explain java-bean Specification
5. How to make a read-only class in Java?
6. How to make a write-only class in Java?
7. What are the advantages of Encapsulation in Java?
Package
1. What is the package?
2. What are the advantages of defining packages in Java?
3. How to create packages in Java?
4. How can we access some class in another class in Java?
5. Do I need to import java.lang package any time? Why?
6. Can I import same package/class twice? Will the JVM load the package twice at
runtime?
7. What is the static import?
Exception-Handling
1. What is an exception?
2. What is exception handling?
3. In how many ways we can handle exception?
4. How many types of exceptions are there?
5. What is checked exception?
6. What is unchecked exception?
7. Can we write more than one catch for single try block?
8. What is generalized catch block
9. What is written with in try block
10. What is written within catch block
11. What is finally block
12. Can we write finally block without catch block
13. Explain the hierarchy of Java Exception classes?
14. What is the difference between Checked Exception and Unchecked Exception?
15. What is the base class for Error and Exception?
16. Is it necessary that each try block must be followed by a catch block?
17. Is there any case when finally will not be executed?
18. What is throw keyword?
19. What is throws?
20. What is the difference between throw and throws?
21. Can an exception be rethrown?
22. Can subclass overriding method declare an exception if parent class method
doesn't throw an exception?
23. What is exception propagation?
Wrapper-class