This is the 9th part of the 500+ Core JAVA interview questions and answers. These questions can also be used as a quick study guide for preparing for an interview or for any Core JAVA concepts revision. These questions cover all the topics in core JAVA from basics to advanced concepts.
1)Can you make a constructor final?
No, constructor can't be final.
static variable is used to refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc.
static variable gets memory only once in class area at the time of class loading.
3)Which class is the superclass for every class.
Object class.
4)What is the purpose of default constructor?
The default constructor provides the default values to the objects. The java compiler creates a default constructor only if there is no constructor in the class.
5)why main method is static?
because object is not required to call static method if It were non-static method,jvm creats object first then call main() method that will lead to the problem of extra memory allocation..
6)Is constructor inherited?
No, constructor is not inherited.
7)Can we execute a program without main() method?
Ans)Yes,one of the way is, by static block.
8)What if the static modifier is removed from the signature of the main method?
Program compiles. But at runtime throws an error "NoSuchMethodError".
9)What is this in java?
It is a keyword that that refers to the current object.
10)Does constructor return any value?
yes, that is current instance (You cannot use return type yet it returns a value).
11)What is composition?
Holding the reference of the other class within some other class is known as composition.
12)What is static block?
Is used to initialize the static data member.
It is excuted before main method at the time of classloading.
13)Can you use this() and super() both in a constructor?
No. Because super() or this() must be the first statement.
14)Can we override the overloaded method?
Yes.
15)What is difference between aggregation and composition?
Aggregation represents weak relationship whereas composition represents strong relationship. For example: bike has an indicator (aggregation) but bike has an engine (compostion).
16)Why method overloading is not possible by changing the return type in java?
Because of ambiguity.
17)What is static method?
A static method belongs to the class rather than object of a class.
A static method can be invoked without the need for creating an instance of a class.
static method can access static data member and can change the value of it.
18)Why Java does not support pointers?
Pointer is a variable that refers to the memory address. They are not used in java because they are unsafe(unsecured) and complex to understand.
19)What is method overriding ?
If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. It is used for runtime polymorphism and to provide the specific implementation of the method..
20)What is covariant return type?
Now, since java5, it is possible to override any method by changing the return type if the return type of the subclass overriding method is subclass type. It is known as covariant return type.
21)What is super in java?
It is a keyword that refers to the immediate parent class object..
22)What is Inheritance?
Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding..
23)Why we cannot override static method?
It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap.
24)What is object cloning?
The object cloning is used to create the exact copy of an object. .
25) Can we overload main() method?
Yes, ofcourse! You can have many main() methods in a class by overloading the main method.
26)Difference between method Overloading and Overriding.
Method overloading increases the readability of the program,Method overriding provides the specific implementation of the method that is already provided by its super class.
method overlaoding is occurs within the class,Method overriding occurs in two classes that have IS-A relationship.
In this case, parameter must be different,In this case, parameter must be same.
27)Can we override static method?
No, you can't override the static method because they are the part of class not object.
28)What is method overloading?
If a class have multiple methods by same name but different parameters, it is known as Method Overloading. It increases the readability of the program..
29)Can you have virtual functions in Java?
Yes, all functions in Java are virtual by default.
30) Why multiple inheritance is not supported in java?
To reduce the complexity and simplify the language, multiple inheritance is not supported in java in case of class.
31)What is final method?
Final methods can't be overriden.
32) What is Runtime Polymorphism?
Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time.
In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.
33) What is the difference between abstraction and encapsulation?
Abstraction hides the implementation details whereas encapsulation hides the data.
Abstraction lets you focus on what the object does instead of how it does it.
34) Can we intialize blank final variable?
Yes, only in constructor if it is non-static. If it is static blank final variable, it can be initialized only in the static block.
35) What is abstraction?
Abstraction is a process of hiding the implementation details and showing only functionality to the user. Abstraction lets you focus on what the object does instead of how it does it.
36)What is final class?
Final class can't be inherited.
37) Can there be any abstract method without abstract class?
No, if there is any abstract method in a class, that class must be abstract.
38)What is final variable?
If you make any variable as final, you cannot change the value of final variable(It will be constant).
39)Can you declare the main method as final?
Yes, such as, public static final void main(String[] args){}.
40) Can you use abstract and final both with a method?
No, because abstract method needs to be overridden whereas you can't override final method.
41) Is it possible to instantiate the abstract class?
No, abstract class can never be instantiated.
42) What is the difference between static binding and dynamic binding?
In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime.
43) What is marker interface?
An interface that have no data member and method is known as a marker interface.For example Serializable,Cloneable etc.
44) What is abstract class?
A class that is declared as abstract is known as abstract class.It needs to be extended and its method implemented.It cannot be instantiated.
45) Can you declare an interface method static?
No, because methods of an interface is abstract bydefault, and static and abstract keywords can't be used together.
46) What is blank final variable?
A final variable, not initalized at the time of declaration, is known as blank final variable.
47)Can you achieve Runtime Polymorphism by data members?
No.
48) What is interface?
Interface is a blueprint of a class that have static constants and abstract methods.It can be used to achive fully abstraction and multiple inheritance.
49)Can an Interface be final?
No, because its implementation is provided by another class.
50)When can an object reference be cast to an interface reference?
An object reference can be cast to an interface reference when the object implements the referenced interface.
Next : 1000+ core JAVA quick study material & interview Questions and Answers
Next : 1000+ core JAVA quick study material & interview Questions and Answers
0 Comment to "Core Java Study guide and interview questions - Part 9"
Post a Comment