java interview Questions
4.23K subscribers
61 photos
23 files
159 links
java interview questions for beginners
Any promotion for
rajp6133@gmail.com
Download Telegram
Can we make constructors static? As we know that the static context (method, block, or variable) belongs to the class, not the object. Since Constructors are invoked only when the object is created, there is no sense to make the constructors static. However, if you try to do so, the compiler will show the compiler error.

For More Questions Visit :- https://cjavapoint.blogspot.com/ πŸ‘ˆπŸ‘ˆπŸ‘ˆπŸ‘ˆ
What is this keyword in java? The this keyword is a reference variable that refers to the current object. There are the various uses of this keyword in Java. It can be used to refer to current class properties such as instance methods, variable, constructors, etc. It can also be passed as an argument into the methods or constructors. It can also be returned from the method as the current class instance. For More Questions Visit :- https://cjavapoint.blogspot.com/
What are the main uses of this keyword ? There are the following uses of this keyword.

1.this can be used to refer to the current class 2.instance variable.
3.this can be used to invoke current class method (implicitly)
4.this() can be used to invoke the current class constructor.
5.this can be passed as an argument in the method call.
6.this can be passed as an argument in the constructor call.
7.this can be used to return the current class instance from the method. For More Questions Visit :- https://cjavapoint.blogspot.com/
Can we assign the reference to this variable? No, this cannot be assigned to any value because it always points to the current class object and this is the final reference in Java. However, if we try to do so, the compiler error will be shown. For More Questions Visit :- https://cjavapoint.blogspot.com/ πŸ‘ˆπŸ‘ˆπŸ‘ˆ
How can constructor chaining be done using this keyword? Constructor chaining enables us to call one constructor from another constructor of the class with respect to the current class object. We can use this keyword to perform constructor chaining within the same class. Consider the following example which illustrates how can we use this keyword to achieve constructor chaining. public class Employee
{
int id,age;
String name, address;
public Employee (int age)
{
this.age = age;
}
public Employee(int id, int age)
{
this(age);
this.id = id;
}
public Employee(int id, int age, String name, String address)
{
this(id, age);
this.name = name;
this.address = address;
}
public static void main (String args[])
{
Employee emp = new Employee(101, 22, "Raj", "Indore");
System.out.println("ID: "+emp.id+" Name:"+emp.name+" age:"+emp.age+" address: "+emp.address);
}

} Questions Visit :- https://cjavapoint.blogspot.com/ πŸ‘ˆπŸ‘ˆπŸ‘ˆπŸ‘ˆ
What is the purpose of a default constructor? The purpose of the default constructor is to assign the default value to the objects. The java compiler creates a default constructor implicitly if there is no constructor in the class. more questions visit:- https://cjavapoint.blogspot.com/
Example:β€”β€”- class Student3{
int id;
String name;

void display(){System.out.println(id+" "+name);}

public static void main(String args[]){
Student3 s1=new Student3();
Student3 s2=new Student3();
s1.display();
s2.display();
}
} more questions visit:- https://cjavapoint.blogspot.com/
Can we overload the constructors? Yes, the constructors can be overloaded by changing the number of arguments accepted by the constructor or by changing the data type of the parameters. Consider the following example. class Test
{
int i;
public Test(int k)
{
i=k;
}
public Test(int k, int m)
{
System.out.println("Hi I am assigning the value max(k, m) to i");
if(k>m)
{
i=k;
}
else
{
i=m;
}
}
}
public class Main
{
public static void main (String args[])
{
Test test1 = new Test(10);
Test test2 = new Test(12, 15);
System.out.println(test1.i);
System.out.println(test2.i);
}
}
What do you understand by copy constructor in Java? There is no copy constructor in java. However, we can copy the values from one object to another like copy constructor in C++.

There are many ways to copy the values of one object into another in java. They are:

By constructor
By assigning the values of one object into another
By clone() method of Object class
Forwarded from java interview Questions
Core java interview QuestionsπŸ‘‰πŸ‘‰πŸ‘‰ Composition
without existing container object if there is no chance of existing contained object
then the relation between container object and contained object is called composition
which is a strong association.
Example:
Any university consists of several departments whenever university object destroys automatically
all the department object will be destroys that is without existing dependent object hence there are associated and this relationship is called composition .more questions visit:- πŸ‘πŸ‘πŸ‘https://cjavapoint.blogspot.com/
Forwarded from java interview Questions (Raj patel)
Without existing container object if there is a chance of existing contained objects
such type of relationship is called aggregation .
in aggregation objects have weak association. https://cjavapoint.blogspot.com/2019/12/aggregation.htmlπŸ‘ˆπŸ‘ˆπŸ‘ˆπŸ‘ŒπŸ‘ŒπŸ‘Œ
 What is meant by Interface?

Answer: Multiple inheritances cannot be achieved in java. To overcome this problem Interface concept is introduced.

An interface is a template which has only method declarations and not the method implementation.
For more questions visit
πŸ‘‰πŸ‘‰https://cjavapoint.blogspot.com/?m=1πŸ‘ˆπŸ‘ˆ
For more questions visitπŸ‘‰πŸ‘‰https://cjavapoint.blogspot.com/?m=1πŸ‘ˆπŸ‘ˆ
What do you like
Anonymous Poll
65%
Core java
17%
Advance java
18%
Spring
What is finally and finalize in java ?

The finally block is used with try-catch to put the code that you want to get executed always, even if an exception is thrown by the try-catch block. finally block is mostly used to release resources created in the try block.

finalize() is a special method in Object class that we can override in our classes. This method gets called by the garbage collector when the object is getting garbage collected. This method is usually overridden to release system resources when the object is garbage collected.

For more questions visit πŸ‘‰πŸ‘‰πŸ‘‰ https://cjavapoint.blogspot.com/?m=1
What is static import?

If we have to use any static variable or method from other class, usually we import the class and then use the method/variable with class name.

import java.lang.Math; //inside class double test = Math.PI * 5;

We can do the same thing by importing the static method or variable only and then use it in the class as if it belongs to it.

import static java.lang.Math.PI; //no need to refer class now double test = PI * 5;

Use of static import can cause confusion, so it’s better to avoid it. Overuse of static import can make your program unreadable and unmaintainable.

More questions visit https://cjavapoint.blogspot.com/?m=1 πŸ‘ˆπŸ‘ˆ
What is Marker interface?

A marker interface is an empty interface without any method but used to force some functionality in implementing classes by Java. Some of the well known marker interfaces are Serializable and Cloneable.

For More questions visit https://cjavapoint.blogspot.com/?m=1 πŸ‘ˆπŸ‘ˆπŸ‘ˆ