Explore topic-wise MCQs in General Awareness.

This section includes 1698 Mcqs, each offering curated multiple-choice questions to sharpen your General Awareness knowledge and support exam preparation. Choose a topic below to get started.

201.

What will be the output of the following PHP code?
 <?php $cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel"); print_r(array_chunk($cars, 2)); ?>  

A. Array ( [0] =&gt; Array ( [1] =&gt; Volvo [2] =&gt; BMW ) [1] =&gt; Array ( [1] =&gt; Toyota [2] =&gt; Honda ) [2] =&gt; Array ( [1] =&gt; Mercedes [2] =&gt; Opel ) )
B. Array ( [1] =&gt; Array ( [1] =&gt; Volvo [2] =&gt; BMW ) [2] =&gt; Array ( [1] =&gt; Toyota [2] =&gt; Honda ) [3] =&gt; Array ( [1] =&gt; Mercedes [2] =&gt; Opel ) )
C. Array ( [0] =&gt; Array ( [0] =&gt; Volvo [1] =&gt; Volvo ) [1] =&gt; Array ( [0] =&gt; BMW [1] =&gt; BMW ) [2] =&gt; Array ( [0] =&gt; Toyota [1] =&gt; Toyota ) )
D. Array ( [0] =&gt; Array ( [0] =&gt; Volvo [1] =&gt; BMW ) [1] =&gt; Array ( [0] =&gt; Toyota [1] =&gt; Honda ) [2] =&gt; Array ( [0] =&gt; Mercedes [1] =&gt; Opel ) )
Answer» E.
202.

What will be the output of the following PHP code?
 <?php $fname = array("Peter", "Ben", "Joe"); $age = array("35", "37", "43"); $c = array_combine($fname, $age); print_r($c); ?>  

A. Array ( Peter Ben Joe )
B. Array ( [Peter] =&gt; 35 [Ben] =&gt; 37 [Joe] =&gt; 43 )
C. Array ( 35 37 43 )
Answer» C. Array ( 35 37 43 )
203.

What will be the output of the following PHP code?
 <?php $a = array("A", "Cat", "Dog", "A", "Dog"); print_r(array_count_values($a)); ?>  

A. Array ( [A] =&gt; 2 [Cat] =&gt; 1 [Dog] =&gt; 2 )
B. Array ( [A] =&gt; 2 [Cat] =&gt; 2 [Dog] =&gt; 1 )
C. Array ( [A] =&gt; 1 [Cat] =&gt; 1 [Dog] =&gt; 2 )
D. Array ( [A] =&gt; 2 [Cat] =&gt; 1 [Dog] =&gt; 1)
Answer» B. Array ( [A] =&gt; 2 [Cat] =&gt; 2 [Dog] =&gt; 1 )
204.

What will be the output of the following PHP code?
 <?php $a1 = array("a"=>"red", "b"=>"green", "c"=>"blue", "d"=>"yellow"); $a2 = array("e"=>"red", "f"=>"green", "g"=>"blue"); $result = array_diff($a1, $a2); print_r($result); ?>  

A. Array ( [d] =&gt; yellow )
B. Array ( [c] =&gt; blue )
C. Array ( [a] =&gt; red )
D. Array ( [e] =&gt; yellow )
Answer» B. Array ( [c] =&gt; blue )
205.

What will happen in this function call?
  <?php function calc($price, $tax) { $total = $price + $tax; } $pricetag = 15; $taxtag = 3; calc($pricetag, $taxtag); ?>  

A. Call By Value
B. Call By Reference
C. Default Argument Value
D. Type Hinting
Answer» B. Call By Reference
206.

What will be the output of the following PHP code?
  <?php function calc($price, $tax="") { $total = $price + ($price * $tax); echo "$total"; } calc(42); ?>  

A. Error
B. 0
C. 42
D. 84
Answer» D. 84
207.

What will be the output of the following PHP code?
  <?php function a() { function b() { echo 'I am b'; } echo 'I am a'; } a(); a(); ?>  

A. I am b
B. I am bI am a
C. Error
D. I am a Error
Answer» E.
208.

What will be the output of the following PHP code?
  <?php $state = array ("Karnataka", "Goa", "Tamil Nadu", "Andhra Pradesh"); echo (array_search ("Tamil Nadu", $state) ); ?>  

A. True
B. 1
C. False
D. 2
Answer» E.
209.

What will be the output of the following PHP code?
  <?php $fruits = array ("apple", "orange", "banana"); echo (next($fruits)); echo (next($fruits)); ?>  

A. Orangebanana
B. Appleorange
C. Orangeorange
D. Appleapple
Answer» B. Appleorange
210.

What will be the output of the following PHP code?
  <?php $fruits = array ("apple", "orange", array ("pear", "mango"), "banana"); echo (count($fruits, 1)); ?>  

A. 3
B. 4
C. 5
D. 6
Answer» E.
211.

What will be the output of the following PHP code?
  <?php $cars = array("Volvo", "BMW", "Toyota"); echo "I like " . $cars[2] . ", " . $cars[1] . " and " . $cars[0] . "."; ?>  

A. like Volvo, Toyota and BMW
B. I like Volvo, BMW and Toyota
C. I like BMW, Volvo and Toyota
D. I like Toyota, BMW and Volvo
Answer» E.
212.

What will be the output of the following PHP code?
  <?php $fname = array("Peter", "Ben", "Joe"); $age = array("35", "37", "43"); $c = array_combine($age, $fname); print_r($c); ?>  

A. Array ( Peter Ben Joe )
B. Array ( [Peter] =&gt; 35 [Ben] =&gt; 37 [Joe] =&gt; 43 )
C. Array ( 35 37 43 )
D. Array ( [35] =&gt; Peter [37] =&gt; Ben [43] =&gt; Joe )
Answer» E.
213.

What will be the output of the following PHP code?
  <?php $a=array("A","Cat","Dog","A","Dog"); $b=array("A","A","Cat","A","Tiger"); $c=array_combine($a,$b); print_r(array_count_values($c)); ?>  

A. Array ( [A] =&gt; 5 [Cat] =&gt; 2 [Dog] =&gt; 2 [Tiger] =&gt; 1 )
B. Array ( [A] =&gt; 2 [Cat] =&gt; 2 [Dog] =&gt; 1 [Tiger] =&gt; 1 )
C. Array ( [A] =&gt; 6 [Cat] =&gt; 1 [Dog] =&gt; 2 [Tiger] =&gt; 1 )
D. Array ( [A] =&gt; 2 [Cat] =&gt; 1 [Dog] =&gt; 4 [Tiger] =&gt; 1 )
Answer» B. Array ( [A] =&gt; 2 [Cat] =&gt; 2 [Dog] =&gt; 1 [Tiger] =&gt; 1 )
214.

What will be the output of the following PHP code?
  <?php $a1 = array("red", "green"); $a2 = array("blue", "yellow"); $a3 = array_merge($a1, $a2); $a4 = array("a", "b", "c", "d"); $a = array_combine($a4, $a3); print_r($a); ?>  

A. Array ( [a] =&gt; blue [b] =&gt; yellow [c] =&gt; red [d] =&gt; green )
B. Array ( [0] =&gt; blue [1] =&gt; yellow [2] =&gt; red [3] =&gt; green )
C. Array ( [0] =&gt; red [1] =&gt; green [2] =&gt; blue [3] =&gt; yellow )
D. Array ( [a] =&gt; red [b] =&gt; green [c] =&gt; blue [d] =&gt; yellow )
Answer» E.
215.

What will be the output of the following PHP code?
  <?php $a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow"); $a2 = array("e" => "red", "f" => "green", "g" => "blue", "h" => "orange"); $a3 = array("i" => "orange"); $a4 = array_combine($a2, $a3); $result = array_diff($a4, $a2); print_r($result); ?>  

A. Array ( [d] =&gt; yellow )
B. Array ( [i] =&gt; orange )
C. Array ( [h] =&gt; orange )
D. Array ( [d] =&gt; yellow [h] =&gt; orange )
Answer» B. Array ( [i] =&gt; orange )
216.

What will be the output of the following PHP code?
  <?php $a1 = array_fill(1, 4, "hello"); $b1 = array_fill(5, 1, "php"); $a2 = array_merge($a1, $a2); print_r($a2); echo "
"; print_r($b1); ?>

A. Array ( [1] =&gt; hello [4] =&gt; hello [5] =&gt; php )
B. Array ( [1] =&gt; hello [2] =&gt; hello [3] =&gt; hello [4] =&gt; hello )
C. Array ( [1] =&gt; hello [2] =&gt; hello [3] =&gt; hello [4] =&gt; hello [5] =&gt; php )
D. Array ( [1] =&gt; hello [2] =&gt; hello [3] =&gt; hello [4] =&gt; hello )
Answer» D. Array ( [1] =&gt; hello [2] =&gt; hello [3] =&gt; hello [4] =&gt; hello )
217.

What will be the output of the following PHP code?
  <?php $names = array("Sam", "Bob", "Jack"); echo $names[0] . "is the brother of " . $names[1] . " and " . $names[1] . "."; ?>  

A. Sam is the brother of Bob and Jack
B. Sam is the brother of Jack and Bob
C. Sam is the brother of Jack and Bob
D. Error
Answer» D. Error
218.

What will be the output of the following PHP code?
  <?php $names = array("Sam", "Bob", "Jack"); echo $names[0] . "is the brother of " . $names[1] . " and " . $names[1] . ".".$brother; ?>  

A. Sam is the brother of Bob and Bob) $brother
B. Sam is the brother of Bob and Bob)
C. $brother
D. Error
Answer» E.
219.

What will be the output of the following PHP code?
  <?php $place = array("NYC", "LA", "Paris"); array_pop($place); $place1 = array("Paris"); $place = array_merge($place, $place1); print_r($place); ?>  

A. Array ( [0] =&gt; LA [1] =&gt; Paris [2] =&gt; Paris )
B. Array ( [0] =&gt; NYC [1] =&gt; LA [2] =&gt; Paris)
C. Array ( [0] =&gt; NYC [1] =&gt; LA [2] =&gt; Paris [3] =&gt; Paris )
D. None of the mentioned
Answer» B. Array ( [0] =&gt; NYC [1] =&gt; LA [2] =&gt; Paris)
220.

What will be the output of the following PHP code?
  <?php $op2 = "blabla"; function foo($op1) { echo $op1; echo $op2; } foo("hello"); ?>  

A. Helloblabla
B. Error
C. Hello
D. Helloblablablabla
Answer» D. Helloblablablabla
221.

What will be the output of the following PHP code?
  <?php function foo($msg) { echo "$msg"; } $var1 = "foo"; $var1("will this work"); ?>  

A. Error
B. $msg
C. 0
D. Will this work
Answer» E.
222.

What will be the output of the following php code?
  <?php $states = array("karnataka" => array ( "population" => "11,35,000", "capital" => "Bangalore"), "Tamil Nadu" => array( "population" => "17,90,000", "capital" => "Chennai") ); echo $states["karnataka"]["population"]; ?>  

A. Karnataka 11,35,000
B. 11,35,000
C. Population 11,35,000
D. Karnataka population
Answer» C. Population 11,35,000
223.

What is the output of this program?
 class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); t.setName("New Thread"); System.out.println(t); } } 

A. Thread[5,main].
B. Thread[New Thread,5].
C. Thread[main,5,main].
D. Thread[New Thread,5,main].
Answer» E.
224.

What is the priority of the thread in output of this program?
 class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); t.setName("New Thread"); System.out.println(t.getName()); } } 

A. Main
B. Thread
C. New Thread
D. Thread[New Thread,5,main].
Answer» D. Thread[New Thread,5,main].
225.

What is the output of this program?
 class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t); } } 

A. Thread[5,main].
B. Thread[main,5].
C. Thread[main,0].
D. Thread[main,5,main].
Answer» E.
226.

What is the priority of the thread in output of this program?
 class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t); } } 

A. 4
B. 5
C. 0
D. 1
Answer» C. 0
227.

What is the name of the thread in output of this program?
 class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t); } } 

A. Main
B. Thread
C. System
D. None of the mentioned
Answer» B. Thread
228.

What is the output of below snippet?
 public class Demo { public static void main(String[] args) { Map sampleMap = new TreeMap(); sampleMap.put(1, null); sampleMap.put(5, null); sampleMap.put(3, null); sampleMap.put(2, null); sampleMap.put(4, null); System.out.println(sampleMap); } }  

A. {1=null, 2=null, 3=null, 4=null, 5=null}
B. {5=null}
C. Exception is thrown
D. {1=null, 5=null, 3=null, 2=null, 4=null}
Answer» B. {5=null}
229.

What will be the output of the program?
 class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); /* Line 5 */ t.run(); /* Line 6 */ } public void run() { for(int i=1; i < 3; ++i) { System.out.print(i + ".."); } } } 

A. This code will not compile due to line 5.
B. This code will not compile due to line 6.
C. 1..2..
D. 1..2..3..
Answer» D. 1..2..3..
230.

What will be the output of the program?
 class Test116 { static final StringBuffer sb1 = new StringBuffer(); static final StringBuffer sb2 = new StringBuffer(); public static void main(String args[]) { new Thread() { public void run() { synchronized(sb1) { sb1.append("A"); sb2.append("B"); } } }.start(); new Thread() { public void run() { synchronized(sb1) { sb1.append("C"); sb2.append("D"); } } }.start(); /* Line 28 */ System.out.println (sb1 + " " + sb2); } } 

A. Main() will finish before starting threads.
B. Main() will finish in the middle of one thread.
C. Main() will finish after one thread.
D. Cannot be determined.
Answer» E.
231.

What will be the output of the program?
 public class ThreadTest extends Thread { public void run() { System.out.println("In run"); yield(); System.out.println("Leaving run"); } public static void main(String []argv) { (new ThreadTest()).start(); } } 

A. The code fails to compile in the main() method
B. The code fails to compile in the run() method
C. Only the text "In run" will be displayed
D. The text "In run" followed by "Leaving run" will be displayed
Answer» E.
232.

What will be the output of the program?
 class s1 extends Thread { public void run() { for(int i = 0; i < 3; i++) { System.out.println("A"); System.out.println("B"); } } } class Test120 extends Thread { public void run() { for(int i = 0; i < 3; i++) { System.out.println("C"); System.out.println("D"); } } public static void main(String args[]) { s1 t1 = new s1(); Test120 t2 = new Test120(); t1.start(); t2.start(); } } 

A. Compile time Error There is no start() method
B. Will print in this order AB CD AB...
C. Will print but not be able to predict the Order
D. Will print in this order ABCD...ABCD...
Answer» D. Will print in this order ABCD...ABCD...
233.

What will be the output of the program?
 class s implements Runnable { int x, y; public void run() { for(int i = 0; i < 1000; i++) synchronized(this) { x = 12; y = 12; } System.out.print(x + " " + y + " "); } public static void main(String args[]) { s run = new s(); Thread t1 = new Thread(run); Thread t2 = new Thread(run); t1.start(); t2.start(); } } 

A. DeadLock
B. It print 12 12 12 12
C. Compilation Error
D. Cannot determine output.
Answer» C. Compilation Error
234.

What will be the output of the program?
 public class ThreadDemo { private int count = 1; public synchronized void doSomething() { for (int i = 0; i < 10; i++) System.out.println(count++); } public static void main(String[] args) { ThreadDemo demo = new ThreadDemo(); Thread a1 = new A(demo); Thread a2 = new A(demo); a1.start(); a2.start(); } } class A extends Thread { ThreadDemo demo; public A(ThreadDemo td) { demo = td; } public void run() { demo.doSomething(); } } 

A. It will print the numbers 0 to 19 sequentially
B. It will print the numbers 1 to 20 sequentially
C. It will print the numbers 1 to 20, but the order cannot be determined
D. The code will not compile.
Answer» C. It will print the numbers 1 to 20, but the order cannot be determined
235.

What will be the output of the program?
 public class WaitTest { public static void main(String [] args) { System.out.print("1 "); synchronized(args) { System.out.print("2 "); try { args.wait(); /* Line 11 */ } catch(InterruptedException e){ } } System.out.print("3 "); } } 

A. It fails to compile because the IllegalMonitorStateException of wait() is not dealt with in line 11.
B. 1 2 3
C. 1 3
D. 1 2
Answer» E.
236.

Which two can be used to create a new Thread?

1. Extend java.lang.Thread and override the run() method.
2. Extend java.lang.Runnable and override the start() method.
3. Implement java.lang.Thread and implement the run() method.
4. Implement java.lang.Runnable and implement the run() method.
5. Implement java.lang.Thread and implement the start() method.

A. 1 and 2
B. 2 and 3
C. 1 and 4
D. 3 and 4
Answer» D. 3 and 4
237.

Which two statements are true?

1. Deadlock will not occur if wait()/notify() is used
2. A thread will resume execution as soon as its sleep duration expires.
3. Synchronization can prevent two objects from being accessed by the same thread.
4. The wait() method is overloaded to accept a duration.
5. The notify() method is overloaded to accept a duration.
6. Both wait() and notify() must be called from a synchronized context.

A. 1 and 2
B. 3 and 5
C. 4 and 6
D. 1 and 3
Answer» D. 1 and 3
238.

The following block of code creates a Thread using a Runnable target:

Runnable target = new MyRunnable();
Thread myThread = new Thread(target);

Which of the following classes can be used to create the target, so that the preceding code compiles correctly?

A. Public class MyRunnable extends Runnable{public void run(){}}
B. Public class MyRunnable extends Object{public void run(){}}
C. Public class MyRunnable implements Runnable{public void run(){}}
D. Public class MyRunnable implements Runnable{void run(){}}
Answer» D. Public class MyRunnable implements Runnable{void run(){}}
239.

What is the output of this program?
 class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { obj1.t.wait(); System.out.print(obj1.t.isAlive()); } catch(Exception e) { System.out.print("Main thread interrupted"); } } } 

A. True
B. False
C. Main thread interrupted
D. None of the mentioned
Answer» D. None of the mentioned
240.

What is the output of this program?
 class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { Thread.sleep(1000); System.out.print(obj1.t.isAlive()); } catch(InterruptedException e) { System.out.print("Main thread interrupted"); } } } 

A. True
B. False
C. Main thread interrupted
D. None of the mentioned
Answer» C. Main thread interrupted
241.

What is the output of this program?
 class newthread extends Thread { Thread t; newthread() { t = new Thread(this,"New Thread"); t.start(); } public void run() { System.out.println(t.isAlive()); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } 

A. 0
B. 1
C. True
D. False
Answer» D. False
242.

What is the output of this program?
 class newthread extends Thread { Thread t1,t2; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } 

A. True
B. False
C. Truetrue
D. Falsefalse
Answer» E.
243.

What is the difference between servlets and applets?

i.Servlets execute on Server; Applets execute on browser

ii.Servlets have no GUI; Applet has GUI

iii.Servlets creates static web pages; Applets creates dynamic web pages

iv.Servlets can handle only a single request; Applet can handle multiple requests

A. I,ii,iii are correct
B. I,ii are correct
C. I,iii are correct
D. I,ii,iii,iv are correct
Answer» C. I,iii are correct
244.

Which are the session tracking techniques?

i. URL rewriting

ii. Using session object

iii.Using response object

iv. Using hidden fields

v. Using cookies

vi. Using servlet object

A. I, ii, iii, vi
B. I, ii, iv, v
C. I, vi, iii, v
D. I, ii, iii, v
Answer» C. I, vi, iii, v
245.

What is the length of the application box made by this program?
 import java.awt.*; import java.applet.*; public class myapplet extends Applet { Graphic g; g.drawString("A Simple Applet",20,20); }  

A. 20
B. Default value
C. Compilation Error
D. Runtime Error
Answer» D. Runtime Error
246.

What is the output of this program?
 import java.lang.reflect.*; class Additional_packages { public static void main(String args[]) { try { Class c = Class.forName("java.awt.Dimension"); Method methods[] = c.getMethods(); for (int i = 0; i < methods.length; i++) System.out.println(methods[i]); } catch (Exception e) { System.out.print("Exception"); } } }  

A. Program prints all the constructors of java.awt.Dimension package
B. Program prints all the methods of java.awt.Dimension package
C. Program prints all the data members of java.awt.Dimension package
D. Program prints all the methods and data member of java.awt.Dimension package
Answer» C. Program prints all the data members of java.awt.Dimension package
247.

What is the output of this program?
 import java.util.*; class Collection_iterators { public static void main(String args[]) { LinkedList list = new LinkedList(); list.add(new Integer(2)); list.add(new Integer(8)); list.add(new Integer(5)); list.add(new Integer(1)); Iterator i = list.iterator(); Collections.reverse(list); Collections.sort(list); while(i.hasNext()) System.out.print(i.next() + " "); } }  

A. 2 8 5 1
B. 1 5 8 2
C. 1 2 5 8
D. 2 1 8 5
Answer» D. 2 1 8 5
248.

What is the output of this program?
 import java.util.*; class LOCALE_CLASS { public static void main(String args[]) { Locale obj = new Locale("URDU") ; System.out.print(obj.getDisplayLanguage()); }  

A. Pakistan
B. PAKISTAN
C. URDU
D. Nothing is displayed
Answer» D. Nothing is displayed
249.

What is the output of this program?
 import java.util.*; class Collection_iterators { public static void main(String args[]) { LinkedList list = new LinkedList(); list.add(new Integer(2)); list.add(new Integer(8)); list.add(new Integer(5)); list.add(new Integer(1)); Iterator i = list.iterator(); Collections.reverse(list); Collections.shuffle(list); i.next(); i.remove(); while(i.hasNext()) System.out.print(i.next() + " "); } }  

A. 2 8 5
B. 2 1 8
C. 2 5 8
D. 8 5 1
Answer» C. 2 5 8
250.

What is the output of this program?
 import java.util.*; class LOCALE_CLASS { public static void main(String args[]) { Locale obj = new Locale("URDU", "PAKISTAN") ; System.out.print(obj.getDisplayLanguage()); } }  

A. Pakistan
B. PAKISTAN
C. URDU
D. Nothing is displayed
Answer» D. Nothing is displayed