Core Java MCQ of Java Full Stack Of Training Set-1

WhatsApp Group Join Now
Telegram Group Join Now
Instagram Group Join Now

1).Emma is writing a program, where she needs to convert a collection to an arraylist Choose the correct option to help her.

Option:

a)ArrayList newList=srcCollection.stream().collect(toCollection(ArrayLists::new));

b)ArrayList<syn> newList= srcCollection.stream().collect(toCollection(ArrayList::new));

c)ArrayList <syn> newList =Collection.stream().collect(toCollection(ArrayList::new));

d)ArrayList <syn>newList= srcCollection.stream().collect (Collection(ArrayList::new));

Answer:-b

2) What will be the output of the following Java code?

public class Main {

public static void main(String[] args) {

int n=10;

int sum = 0;

for (int i = 0; i < n; i++) {

for (int j = 1; j < n; j++) {

sum + =i + j;

     }

}

System.out.println(sum);

        }

}

Option:
a)330

b)660

c)495

d)990

Answer:-c)495

3).class ImmutableString{

public static void main(String args[]){

String str=kate”;

str.concat(” Williams”);

System.out.println(str);

        }

}

Predict the output?

Options:-

a).kate

b).Kate Williams

c).null

d).comptation error

Answer:-b).Kate Williams

4).Find the output of the code below:

class multithread

{

public static void main(String args[])

{

Thread t = Thread.currentThread();

System.out.println(t);

        }

}

Options:-

a)Thread[5,main]

b)Thread[main, 5, main]

c)Thread[main 0]

d)Thread [main 5]

Answer:-b)Thread[main, 5, main]

5).Which of the following are true statements about serialization in Java?

(Choose two options)

Answer

Please choose all correct answers

a)The Senalizable interface declares the serialize() method

b).Senakizable is a functional interface

c).All threads are serializable

d).Deserialization is the process of turning a serialized stream back into an object.

e).An object can be serialized only if it implements the Serializable interface and contains instance variables that are serializable or marked transient

f)objects of final classes cannot be senalized

Answer:-(d) and (e)

6)In a Java assignment, the student is using a switch statement as given below

String alpha=”a”

switch(a) {

. .

. . .

}

The above code segment would not run for

Answer

Please choose a correct answer.

1)Java 5

2)Java 6

3)Java 7

 4)Both 1 and 2

Answer:-4)Both 1 and 2

7)What will be the output of the code below?

public class MyThread extends Thread {

public void run() {

System.out.println(this.getName());

}

public static void main(String args[]) {

MyThread thread1 =new MyThread();

MyThread thread2=new MyThread();

thread1.start();

thread2.start();

       }

}

1).Thread-0

Thread-1

2).Thread 1

Thread2

3).Thread 0

Thread 1

4)Thread0

Thread1

Answer :-

1).Thread-0

Thread-1

8)What will be the output of the following Java code?

public class Main {

public static void main(String[] args) {

int n=5;

int s=0;

for (int i=0; i < n; i++) {

for (int j =1; j < n; j++) {

for (int k=j; k < n; k++) {

  s++;

        }

    }

}

System.out.println(s);

       }

}

Options:-

1)15

2)35

3)70

4)125

Answer:-2)35

9) Which of the following is a valid identifier?

Answer

Please choose a correct answer.

1)DoSelect labs
 

2)2way

3)$_

4)new

5)default

Answer:-3)$_

10)When an application starts, only a single thread runs.

This thread is known as?

Answer

Please choose a correct answer.

1)Centre Thread

2)Priority Thread

3)First Thread

4)Main Thread

Answer:-4)Main Thread