In this post, we have a top ask java interview questions nowadays core java interview questions are asked in every java interview.

core java interview questions
Core java Aptitude interview questions

They also try to take java aptitude questions or java aptitude test this java interview questions will give a knowledge that how a core java interview questions aptitude test has been asked.

Q1)What is the following output of this Java Interview Questions Program.
public static void main(String[] args)  {

System.out.println("Output:"+null.length());

}

A) java.lang.NullPointerException
B) Compile Time Error
C) Output:4
D) Output:0

OUTPUT :

Q2) What is the following output of this Java Interview Questions Program.
public static void main(String[] args)  {

	String str=null;
	str.length();
	System.out.println("test");	
	
	}
    

A) Compile Time Error
B) java.lang.NullPointerException
C) java.lang.NullPointerException and "Test"
D) "Test"

OUTPUT:

Q3)What is following out of this Java Interview Questions Program.
public class Java_Question {
	private final int first;
	private final int second;

	public Java_Question(int first, int second) {
		this.first = first;
		this.second = second;
	}

	public int getFirst() {
		return first;
	}

	public int getSecond() {
		return second;
	}

	public static Java_Question something() {
		int number1 = 1;
		int number2 = 2;

		return new Java_Question(number1, number2);
	}

	public static void main(String[] args) {
		Java_Question result = something();
		System.out.print("Output:");
		System.out.println(result.getFirst() + result.getSecond());
	}
}


A) Compile Time Error
B) Output:12
C) Output:3
D) Runtime error

OUTPUT:

Q4)What is the following output of this Java Interview Questions Program.
public class CheckReturn {

public static void main(String[] args) {
	int a=10;
	System.out.println("hello ");
	if(true){
		return;
	}
	System.out.print(" hello world");
	
}
}

A) You cannat used return in Main Method
B) "hello"
C) "hello hello world"
D) Compile Time Error

OUTPUT:

Q5)What is the following output of this Java Interview Questions Program.
interface I1{
	void show();
}
interface I2{
	void show();
}

public  class Test implements I1,I2 {
	@Override
	public void show() {
		// TODO Auto-generated method stub
		
	}
}

A)Above code works fine
B) Ambiguity Error in Java, a class can't override two show() method
C) You Cannot implement two interface at a Time.
D) Compile Fails

OUTPUT:

6) In the below example, how many String Objects are created?
	String s1="I am learning java";
	String s3="I am learning java";
	String s2="I am learning C";
	String s4="I am learning java";
	String s5="I am learning C";

A) Five Object
B) Three Object
C) Two Object
D) One Object

OUTPUT:

7) There are two types of the class named Test and Test2. Both classes are in the same package.
Then what is the output of the below core java interview questions program?
class Test2 {
	
 private int  num=10;
 
}

public class Test {

	public void show(Test2 test) {
		
		System.out.println("Output:"+test.num);
		}
	
	public static void main(String[] args) {
		Test2 test2=new Test2();

		Test test=new Test();
		test.show(test2);
	

A) Output :10.
B) Output :0.
C) Test2 does have any num variable.
D) Private members of the class aren't accessible.

OUTPUT:

8) How can we restrict extend for a class so that no class can be inherited from it.
A)Make Class as Private
B)Make Class as Final
C)Make Class as Public
D)Make Class as Protected


OUTPUT:

9)How we can not allow variables to be in a part of serialization.
A) Use static keyword on variable.
B) Use this private Keyword on variable.
C) Use this final Keyword on variable.  
D) Use this transient Keyword on variable. 

OUTPUT:

10) Is this Code Java class Declaration is correct?
public abstract final class DemoClass{
//
}


A) Incorrect
B) Correct

OUTPUT:

11)Can we write an interface inside a class.
public class InsideInterface {
	interface I1 {
	}

}

A) Incorrect
B) Correct

OUTPUT:

12) Is this following java program incorrect.
Can we extend two interfaces at a time?
interface I1{
	
}

interface I2{
	
}

interface I3 extends I1,I2{
	
}

A) Incorrect
B) Correct

OUTPUT:

13)What is following out of this Java Interview Questions Program.
public class Test {
	
	private String name;

	public Test(String name) {
		this.name = name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}

	private void test(final Test n) {
		
		System.out.print (n.getName()+"  ");
		n.setName("Hello");
		System.out.println( n.getName());
		
	}

	public static void main(String[] args) {
		Test tes = new Test("ziyad");
		tes.test(tes);
	}
}

A) Compile Time Error we cannot reassign a final variable
B) ziyad Hello
C) ziyad ziyad
D) Private variables of the class aren't accessible.

OUTPUT:

14)What happens if an exception is thrown in finally block? Is the remaining finally executed or not?
A)Wheather Exception occur or not Finally always execute, and remaining code also.
B)Compile Time error exception is not thrown in finally block. 
C)No remaining code not executed when exception in finally block.
D)No Exception can be thrown in Finally block.

OUTPUT:

15)What is following out of this Java Interview Questions Program.
public class Test {

	public static void main(String[] args) {
		String str = "Hello Ziyad";
		if (str instanceof String) {
			System.out.print("True  ");
		} else {
			System.out.print("  False");
		}

		String str1 = null;
		if (str1 instanceof String) {
			System.out.println("True  ");
		} else {
			System.out.println(" False");
		}
	}
}
 

A) True True
B) False False
C) False True
D) True False

OUTPUT:

If you have come to the end of this core java interview questions then you also need to check Java 8 interview questions and also core java interview questions


I hope you enjoy this Code, do comment aptitude questions which you know!

Post a Comment

Previous Post Next Post