Java Programming (3350703) MCQs

MCQs of Exception Handling & Multithreaded Programming

Showing 31 to 40 out of 48 Questions
31.

Which method is used to get current running thread object?

(અત્યારે જે થ્રેડ રન થાય છે તેનો ઓબ્જેક્ટ મેળવવા કઈ મેથડનો ઉપયોગ થાય છે?)

(a)

currentThread()

(b)

runningThread()

(c)

runnableThread()

(d)

Thread()

Answer:

Option (a)

32.

The life cycle of a thread in java is controlled by ______.

(Javaમા થ્રેડની લાઈફ સાયકલ __________ દ્વારા કંટ્રોલ કરવામાં આવે છે.)

(a)

JDK

(b)

JVM

(c)

JRE

(d)

jar

Answer:

Option (b)

33.

Which of the following are valid constructors for Thread?

1) Thread()

2) Thread(int priority)

3) Thread(Runnable r, String name)

4) Thread(Runnable r, int priority)

થ્રેડ માટે નીચે આપેલમાંથી ક્યા કન્સ્ટ્રક્ટર વેલીડ છે?

1) Thread()

2) Thread(int priority)

3) Thread(Runnable r, String name)

4) Thread(Runnable r, int priority)

(a)

1 and 2 

(1 અને 2)

(b)

1 and 3

(1 અને 3)

(c)

2 and 3

(2 અને 3)

(d)

2 and 4

(2 અને 4)

Answer:

Option (b)

34.

How many threads will running during execution of  below given Java program?

class DThread extends Thread 
{ 
   public void run() 
   { 
      System.out.println("Run called"); 
   } 
}
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
   } 
} 

નીચે આપેલ પ્રોગ્રામના એક્ઝીક્યુશન દરમિયાન કેટલા થ્રેડ રન થશે?

class DThread extends Thread 
{ 
   public void run() 
   { 
      System.out.println("Run called"); 
   } 
}
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
   } 
} 
(a)

0

(b)

1

(c)

2

(d)

Depend upon operating system

ઓપરેટીંગ સિસ્ટમ પર આધાર રાખે છે

Answer:

Option (b)

35.

What will be the output of following code?

class DThread extends Thread 
{ 
   public void run() 
   { 
      System.out.print("Run called "); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
      System.out.print("Main method ");
   } 
} 

નીચે આપેલ કોડનું આઉટપુટ શું આવશે?

class DThread extends Thread 
{ 
   public void run() 
   { 
      System.out.print("Run called "); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
      System.out.print("Main method ");
   } 
} 
(a)

Main method Run called

(b)

Run called Main method

(c)

Run called

(d)

Depend upon JVM

JVM પર આધાર રાખશે

Answer:

Option (b)

36.

What will be the output of following code?

class DThread implements Runnable 
{ 
   public void run() 
   { 
      System.out.println("Run called"); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      Thread  t = new Thread(); 
      t.start(); 
      System.out.println("Main method"); 
   } 
}

નીચે આપેલ કોડનું આઉટપુટ શું આવશે?

class DThread implements Runnable 
{ 
   public void run() 
   { 
      System.out.println("Run called"); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      Thread  t = new Thread(); 
      t.start(); 
      System.out.println("Main method"); 
   } 
}
(a)

Run called

(b)

Main method

(c)

Run called Main method

(d)

Compilation error

કમ્પાઈલેશન એરર

Answer:

Option (b)

37.

Which of following is true about notifyAll()?

(notifyAll() માટે નીચે આપેલમાંથી કયું વિધાન સાચું છે?)

(a)

Wakes up all thread  that are waiting on this object's monitor

(એક જ ઓબ્જેક્ટના મોનીટર પર વેઈટ કરતા બધા થ્રેડ વેકઅપ થશે)

(b)

Wakes up all thread  that are not waiting on this object's monitor

(એક જ ઓબ્જેક્ટના મોનીટર પર વેઈટ કરતા બધા થ્રેડ વેકઅપ થશે નહિ)

(c)

Wakes up only one thread that are waiting on this object's monitor

(એક જ ઓબ્જેક્ટના મોનીટર પર વેઈટ કરતા બધા થ્રેડમાંથી ફક્ત એક જ થ્રેડ વેકઅપ થશે)

(d)

Wakes up only two thread that are waiting on this object's monitor

(એક જ ઓબ્જેક્ટના મોનીટર પર વેઈટ કરતા બધા થ્રેડમાંથી  ફક્ત બે જ થ્રેડ વેકઅપ થશે)

Answer:

Option (a)

38.

What will be the output of following code?

class DThread extends Thread 
{ 
   public void start() 
   { 
      System.out.println("Start called "); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
   } 
} 

નીચે આપેલ કોડનું આઉટપુટ શું આવશે?

class DThread extends Thread 
{ 
   public void start() 
   { 
      System.out.println("Start called "); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
   } 
} 
(a)

Runtime error that indicates there is no run() method defined

રનટાઈમ એરર આવશે જે દર્શાવે છે કે તેમાં run() મેથડ ડિફાઇન કરેલ નથી

(b)

Compile time error that indicates there is no run() method defined

કમ્પાઈલટાઈમ એરર આવશે જે દર્શાવે છે કે તેમાં run() મેથડ ડિફાઇન કરેલ નથી

(c)

Compile successfully and no output display during execution

કમ્પાઈલ થશે અને એક્ઝીક્યુશન દરમ્યાન કઈ આઉટપુટ આવશે નહિ

(d)

Start called

Answer:

Option (c)

39.

Which of the following keyword is applied on a method  indicates that only one thread should execute the method at time?

(નીચે આપેલમાંથી કયો કીવર્ડ મેથડમા અપ્લાય કરવાથી કોઈ એક સમયે ફક્ત એક જ થ્રેડ એ મેથડને એક્ઝીક્યુટ કરી શકે છે?)

(a)

final

(ફાઇનલ)

(b)

static 

(સ્ટેટિક)

(c)

synchronized

(સિન્ક્રોનાઇઝ્ડ)

(d)

super

(સુપર)

Answer:

Option (c)

40.

What will be the output of following code?

class DThread extends Thread 
{ 
   public void run() 
   { 
      System.out.print("hello"); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
      t.run(); 
      t.start(); 
   } 
}

નીચે આપેલ કોડનું આઉટપુટ શું આવશે?

class DThread extends Thread 
{ 
   public void run() 
   { 
      System.out.print("hello"); 
   } 
} 
class DemoThread 
{ 
   public static void main(String[] args) 
   { 
      DThread  t = new DThread(); 
      t.run(); 
      t.run(); 
      t.start(); 
   } 
}
(a)

Compilation error

કમ્પાઈલેશન એરર

(b)

hello

(c)

hellohello

(d)

hellohellohello

Answer:

Option (d)

Showing 31 to 40 out of 48 Questions