Java MCQ Multiple Choice Question and answer

Java Programming OOPs

Java MCQ Multiple Choice Question and answer


1.
The default value of a static integer  variable of a class in Java is,
(a)  0                       (b)  1                       (c)  Garbage value   (d)  Null    (e)  -1.

Answer : (a)
Reason:  The default value of a static integer  variable of a class in Java is 0.

2.
What will be printed as the output of the following program?
                  public class testincr
                  {
                  public static void main(String args[])
                  {
                     int i = 0;
                     i = i++ + i;
                     System.out.println("I = " +i);
                   }
                   }
(a)  I = 0           (b)  I = 1           (c)  I = 2                (d)  I = 3                (e)  Compile-time Error.

Answer : (b)
Reason:  1
                The execution goes on like this:
                          int i = 0;    //  i becomes 0
                          i = 0 + i;  //    now, i becomes 1
                          i = 0 + 1;  //    perform addition and assign 1 to i.

3.
Multiple inheritance means,
(a)   one class inheriting from more super classes
(b)   more classes inheriting from one super class
(c)   more classes inheriting from more super classes
(d)   None of the above
(e)   (a) and (b) above.

Answer : (a)
Reason:  Multiple inheritance means one class inheriting from more super classes.

4.
Which statement is not true in java language?
(a)   A public member of a class can be accessed in all the packages.
(b)   A private member of a class cannot be accessed by the methods of the same class.
(c)   A private member of a class cannot be accessed from its derived class.
(d)   A protected member of a class can be accessed from its derived class.
(e)   None of the above.

Answer : (b)
Reason:  Private members of a class can be accessed by the methods within the same class.

5.
To prevent any method from overriding, we declare the method as,
(a)  static        (b)  const            (c)  final              (d)  abstract             (e)  none of the above.

Answer : (c)
Reason:  Final methods of the base class cannot be overridden in the derived Class.

6.
Which one of the following is not true?
(a)   A class containing abstract methods is called an abstract class.
(b)   Abstract methods should be implemented in the derived class.
(c)   An abstract class cannot have non-abstract methods.
(d)   A class must be qualified as ‘abstract’ class, if it contains one abstract method.
(e)   None of the above.

Answer : (c)
Reason:  An abstract class can contain both abstract and non-abstract methods.

7.
The fields in an interface are implicitly specified as,
(a)  static only                                        (b)  protected                                        (c)  private
(d)  both static and final                         (e)  none of the above.

Answer : (d)
Reason:  The fields in an interface are implicitly specified as both static and final.

8.
What is the output of the following program:
                       public class testmeth
                       {
                           static int i = 1;
                           public static void main(String args[])
                            {
                                 System.out.println(i+” , “);
                                 m(i);
                                 System.out.println(i);
                            }
                            public void m(int i)
                            {
                               i += 2;                              
                            }
                       }
(a)  1 , 3                  (b)  3 , 1                  (c)  1 , 1                  (d)  1 , 0        (e)  none of the above.
Answer : (c)
Reason:  Parameter values are passed by value in the calling of a method, and  so a copy of the value is created in the method, and the original value is not affected by the method call.


9.
Which of the following is not true?
(a)   An interface can extend another interface.
(b)   A class which is implementing an interface must implement all the methods of the interface.
(c)   An interface can implement another interface.
(d)   An interface is a solution for multiple inheritance in java.
(e)   None of the above.

Answer : (c)
Reason:  An interface can extend another interface but not implement.

10.
Which of the following is true?
(a)   A finally block is executed before the catch block but after the try block.
(b)   A finally block is executed, only after the catch block is executed.
(c)   A finally block is executed whether an exception is thrown or not.
(d)   A finally block is executed, only if an exception occurs.
(e)   None of the above.

Answer : (c)
Reason:  A finally block is executed whether an exception is thrown or not is correct.



11.
Among these expressions, which is(are) of type String?
(a)  "0"                                                   (b)  "ab" + "cd"                                      
(c)  '0' 
(d)  Both (A) and (B) above                    (e)  (A), (B) and (C) above.

Answer : (d)


Reason:  Strings are  "0" and "ab" + "cd" .

12.
Consider the following code fragment
                  Rectangle r1 = new Rectangle();
                  r1.setColor(Color.blue);
                  Rectangle r2 = r1;
                  r2.setColor(Color.red);

             After the above piece of code is executed, what are the colors of r1 and  


             r2 (in this order)?  
(a)   Color.blue
       Color.red
(b)   Color.blue
       Color.blue
(c)   Color.red
       Color.red
(d)   Color.red
       Color.blue
(e)   None of the above.

Answer : (c)


Reason:  Both r1 and r2 are referring the same object of Rectangle class. So, finally the Color of the object is changed to red.

13.
What is the type and value of the following expression? (Notice the integer division)
                   -4 + 1/2 + 2*-3 + 5.0
(a)  int -5                                                (b)  double -4.5                                      
(c)  int -4                             
(d)  double -5.0                                      (e)  None of the above.

Answer : (d)


Reason:  The execution goes on like this:
-4 + 1/2 + 2*-3 + 5.0;


-4 +  0 +  -6 +  5.0;  // integer division: 1/2 truncates .5
-10 +  5.0;  // higher type is double 5.0, so -10 is casted to double


-5.0;  //  finally, double -5.0.

14.
What is printed by the following statement?
System.out.print("Hello,\nworld!");
(a)  Hello, \nworld!   (b)  Hello, world!                                   
(c) 
(d)  "Hello, \nworld!" (e)  None of the above.

Answer : (c)


Reason:  The statement 
gives output as
System.out.print("Hello,\nworld!");



15.
Consider the two methods (within the same class)
         public static int foo(int a, String s)
         {
           s = "Yellow";
           a=a+2;
           return a;
         }
         public static void bar()
         {
           int a=3;
           String s = "Blue";
           a = foo(a,s);
           System.out.println("a="+a+" s="+s);
         }
         public static void main(String args[])
         {
            bar();
         }
What is printed on execution of these methods?
(a)  a = 3 s = Blue                                  (b)  a = 5 s = Yellow                                           (c)  a = 3 s = Yellow
(d) a = 5 s = Blue                                   (e) none of the above.

Answer : (d)


Reason:  ‘a’ value is returned from the method and so it is 5. But the string will remain same, as it is passed by value to the method.

16.
Which of the following variable declaration would NOT compile in a java program?
(a)  int var;               (b)  int VAR;            (c)  int var1;             (d)  int var_1;           (e)  int 1_var;.

Answer : (e)


Reason:  The first character of a variable name should not be a digit.

17.
Consider the following class definition:
            public class MyClass
            {
            private int value;
            public void setValue(int i){ /* code */ }
            // Other methods...
            }
The method setValue assigns the value of i to the instance field value. What could you write for the implementation of setValue?
(a)  value = i;                                         (b)  this.value = i;                                (c)  value == i;
(d)  Both (A) and (B) and above              (e)  (A), (B) and (C) above.

Answer : (d)


Reason:  ‘==’ is a comparison operator.


18.
Which of the following is TRUE?
(a)   In java, an instance field declared public generates a compilation error.
(b)   int is the name of a class available in the package java.lang
(c)   Instance variable names may only contain letters and digits.
(d)   A class has always a constructor (possibly automatically supplied by the java compiler).
(e)   The more comments in a program, the faster the program runs.

Answer : (d)


Reason:  A class will always have a constructor, either provided by the user or a default constructor provided by the compiler.

19.
A constructor
(a)   Must have the same name as the class it is declared within.
(b)   Is used to create objects.
(c)   May be declared private
(d)   Both (A) and (B) above
(e)   (a), (b) and (c) above.

Answer : (e)


Reason:  A constructor
·                    Must have the same name as the class it is declared within.


·         
           Is used to create objects.
·                    May be declared private.


20.
Consider,
              public class MyClass
              {
              public MyClass(){/*code*/}
               // more code...
               }
To instantiate MyClass, you would write?
(a)   MyClass mc = new MyClass();
(b)   MyClass mc = MyClass();
(c)   MyClass mc = MyClass;
(d)   MyClass mc = new MyClass;
(e)   The constructor of MyClass should be defined as, public void MyClass(){/*code*/}.

Answer : (a)


Reason:  An object is created by using a new operator.



जनसंख्या वृद्धि विषय पर सारगर्भित निबन्ध

जनसंख्या वृद्धि विषय पर सारगर्भित निबन्ध लिखिए।

विज्ञान की देन विषय पर निबन्ध

 विज्ञान की देन विषय पर सारगर्भित निबन्ध लिखिए

वन संरक्षण विषय पर निबंध

 वन संरक्षण। विषय पर सारगर्भित निबंध लिखिए : (200 से 250 शब्दों में)

विज्ञान के बढ़ते चरण निबंध (200 से 250 शब्दों में)

विज्ञान के बढ़ते चरण। विषय पर सारगर्भित निबंध लिखिए : (200 से 250 शब्दों में)

जल ही जीवन है पर निबंध (Jal Hi Jeevan Hai Essay In Hindi) (200 से 250 शब्दों में)

  जल ही जीवन है। विषय पर सारगर्भित निबंध लिखिए : (200 से 250 शब्दों में)

आधुनिक भारत में नारी। विषय पर सारगर्भित निबंध लिखिए : (200 से 250 शब्दों में)

 आधुनिक भारत में नारी। विषय पर सारगर्भित निबंध लिखिए : (200 से 250 शब्दों में)

साहित्य और समाज विषय पर सारगर्भित निबंध लिखिए

 साहित्य और समाज विषय पर सारगर्भित निबंध लिखिए : (200 से 250 शब्दों में)

अपने बड़े भाई की शादी में अपने मित्र को आमंत्रित करने के लिये पत्र लिखिए

अपने बड़े भाई की शादी में अपने मित्र को आमंत्रित करने के लिये पत्र लिखिए

परीक्षा काल में ध्वनि-विस्तारक यन्त्रों के बजाने पर रोक लगाने हेतु जिलाधीश को प्रार्थना पत्र लिखिए

परीक्षा काल में ध्वनि-विस्तारक यन्त्रों के बजाने पर रोक लगाने हेतु जिलाधीश को प्रार्थना पत्र लिखिए।

ध्वनि प्रदूषण रोकने के लिए पुलिस अधीक्षक को पत्र

 

Letter to Superintendent of Police for restraining the Noise Pollution in Hindi | Dhawni Pradushan ko rokne ke liye Police Adhikshak ko Patra

पिताजी से रुपए मंगवाने के लिए पत्र लिखें | Write Letter to your father for money in Hindi

 

Write Letter to your father for money in Hindi | Pita ko Rupaye Mangawane ke liye Patra

जन्मोत्सव में उपस्थित न हो पाने हेतु मित्र को पत्र | Letter to friend for not attending her birthday party in Hindi

Letter to your friend for not attending her birthday party in Hindi | 

Janmotsav men upasthit na ho sakne hetu mitra ko Patra

एक सप्ताह के अवकाश के लिए प्रार्थना पत्र | school leave application for fever in hindi

 

Application to the Principal of your school granting leave for one week' in Hindi | 'Pradhanacharya ko ek saptah ke avakash ke liye Prarthnapatra'

स्थानांतरण प्रमाण पत्र हेतु प्रार्थनापत्र || TC Transfer Certificate Application in Hindi

 

Application to the Principal of school for issuance of Transfer Certificate in Hindi | Sthanantaran Pramanpatra hetu Prarthnapatra

छात्रवृत्ति हेतु प्रधानाचार्य को प्रार्थनापत्र || Application to the Principal of school for grant of Scholarship

 

'Application to the Principal of your school for grant of Scholarship' in Hindi | 'Chhatravritti hetu Pradhanacharya ko Prarthnapatra'

computer architecture mcq with answers

Questions 111 To 120

Computer Organization and Architecture Question Bank with answers

 

Questions 81 To 90


81.
A machine cycle refers to
(a)
Fetching an instruction
(b)
Clock speed
(c)
Fetching, decoding and executing  an instruction
(d)
Executing and instruction
(e)
Decoding an instruction.
82.
The System bus is made up of
(a)
Control bus
(b)
Address bus
(c)
Both Control bus and Address bus
(d)
Control bus, Data bus and Address bus
(e)
Data bus.
83.
The code used to boot up a computer is stored in
(a)
RAM
(b)
ROM
(c)
PROM
(d)
EPROM
(e)
EEPROM.
84.
In accessing a disk block the longest delay is due to
(a)
Rotation time
(b)
Seek time
(c)
Transfer time
(d)
Clock speed
(e)
Access time.
85.
Which of the following is/are not part(s) of the CPU?
(a)
ALU
(b)
The Control unit
(c)
The Registers
(d)
System bus
(e)
All of the above.
86.
Memory mapped  I/O  involves transferring of
(a)
Information between memory locations
(b)
Information between registers and memory
(c)
Information between CPU and I/O devices
(d)
Information between CPU and  Memory
(e)
Information between I/O devices and CPU.
87.
Name the type of memory that can be erased with the electric discharge?
(a)
ROM
(b)
EPROM
(c)
RAM
(d)
EEPROM
(e)
PROM.
8.
What is the units for measuring the CPU performance?
(a)
BPS
(b)
MIPS
(c)
MHz
(d)
VLSI
(e)
KHz.


89.
The read/write line belongs to
(a)
The data bus
(b)
The control bus
(c)
The address bus
(d)
CPU bus
(e)
System bus.
90.
Busy waiting is a technique
(a)
To allow the CPU wait for a busy device
(b)
To allow a busy device wait for the CPU
(c)
To keep an idle device busy
(d)
To improve CPU performance
(e)
To keep a device busy.

Answers


81.
Answer :   (c)
Reason  :  A machine cycle refers to Fetching, decoding and executing  an instruction.
82.
Answer :   (d)
Reason  :  System bus consists of a Control bus, Data bus and a Address bus.
83.
Answer :   (b)
Reason  :  The bootable code is stored in ROM.
84.
Answer :   (e)
Reason  :  Access time.
85.
Answer :   (d)
Reason  :  System bus is not a part of a cpu .
86.
Answer :   (e)
Reason  :  Memory mapped I/O involves transferring information between I/O devices and CPU .
87.
Answer :   (d)
Reason  :  EEPROM is the type of memory whose contents is erased with the passage of electiricity.
88.
Answer :   (c)
Reason  :  CPU performance is measured in MHz
89.
Answer :   (c)
Reason  :  The read / write line belongs to the address bus.a
90.
Answer :   (a)
Reason  :  Busy waiting is to allow the CPU wait for a busy device.


Questions 91 To 100


91.
Which of the following Addressing Modes specifies a register which contains the memory address of the operand?
(a)
Indirect Addressing Mode
(b)
Register Addressing Mode
(c)
Register Indirect Addressing Mode
(d)
Index Addressing  Mode
(e)
Base Address Register Addressing Mode.
92.
Identify the term, which indicate a set of Logical Addresses.
(a)
Memory space
(b)
Disk space
(c)
Address space
(d)
Location
(e)
Page frame.
93.
Which of the following is false related to Stack?
(a)
Stack Pointer points to the top most element of the stack
(b)
Only PUSH and POP operations are applicable
(c)
Implements FIFO
(d)
Useful for nested loops, subroutine calls etc
(e)
Efficient for arithmetic expression evaluation.

94.
Which of the following is the method in which the unit receiving the data responds with another control signal?
(a)
Timing sequence
(b)
Synchronous
(c)
Strobe
(d)
Short message service
(e)
Handshaking.
95.
What is the page replacement algorithm in which there is a replacement of a page, which will not be used for the longest period of time?
(a)
MFU
(b)
LRU
(c)
OPT
(d)
FIFO
(e)
LFU.
96.
Of the following, what is an input device for which finger shows the cursor movement?
(a)
Mouse
(b)
Scanner
(c)
Microphone
(d)
Trackball
(e)
Glide pad.
97.
Consider the following unsigned  decimal numbers:
i.       6543.
ii.      4444.
What is the result after subtracting (i) by taking the 10's complement of (ii)?
(a)
2098
(b)
2099
(c)
2096
(d)
2097
(e)
2095.
98.
What is the octal equivalent of given binary number?
011001
(a)
32
(b)
31
(c)
34
(d)
33
(e)
35.
99.
Which of the following describes the Mnemonic SPA?
(a)
Skip If (Address Resister) Positive
(b)
Skip If (Accumulator) Positive
(c)
Skip If (Adder-Subtractor) Positive
(d)
Skip If (Associative Mapping) Positive
(e)
Skip If (Assembler) Positive.

lala

100.
Which of the following is correct related to the circuit diagrams?
(a)
Sequential circuit is an interconnection of only logic gates
(b)
Sequential circuit is an interconnection of only flip flops
(c)
Combinational circuit is an interconnection of  logic gates
(d)
Combinational circuit is an interconnection of flip flops
(e)
Part of a combinational circuit is a sequential circuit.

Answers


91.
Answer :       (c)
Reason:  Addressing mode that specifies a register which contains the memory address of the operand is  Register Indirect Addressing Mode.
92.
Answer :       (c)
Reason:  Address space indicate a set of Logical Addresses.
93.
Answer :       (c)
Reason:  Stack does not Implement FIFO but implements LIFO.
94.
Answer :       (e)
Reason:  Handshaking is the method in which the unit receiving the data responds with another control signal.
95.
Answer :       (c)
Reason:  The page replacement algorithm in which there is a replacement of a page, which will not be used for the longest period of time is OPT.
96.
Answer :       (e)
Reason:  The input device for which finger shows the cursor movement is Glide pad.
97.
Answer :       (b)
Reason:  6543- 4444= 2099
98.
Answer :       (b)
Reason:  The octal equivalent of  011001 =31.
99.
Answer :       (b)
Reason:  SPA stands for Skip If (Accumulator) Positive
100.
Answer :       (c)
Reason:  Combinational circuit is an interconnection of logic gates.


Questions 101 To 110


101.
Of the following, identify the memory usually written by the manufacturer.
(a)
RAM
(b)
DRAM
(c)
SRAM
(d)
ROM
(e)
Cache Memory.
102.
What does D stands for in D-flip flop?
(a)
Direct
(b)
Don’t care
(c)
Double
(d)
Delay
(e)
Data.
103.
Consider that the program is executed from main memory until it attempts to reference a page that is still in auxiliary memory. Identify this condition.
(a)
Page Found
(b)
Page Fault
(c)
Page Hit
(d)
Page Miss
(e)
Page Replace.

104.
DMA stands for
(a)
Direct Memory Address
(b)
Direct Main Address
(c)
Direct Memory Access
(d)
Direct Main Access
(e)
Device Memory Access.
105.
What is the symbol to represent a state in the state diagram?
106.
Consider DR ← M [AR], Identify the operation.
(a)
Arithmetic Operation
(b)
Shift Operation
(c)
Memory Write
(d)
Memory Read
(e)
Memory Cycle.
107.
A computer has memory of 256k words of 32 bits each, how many bits are required to specify the address part?
(a)
16 bits
(b)
12 bits
(c)
  8 bits
(d)
18 bits
(e)
10 bits.
108.
Which one of the following can be called as a peripheral?
(a)
Control Unit
(b)
Arithmetic Unit
(c)
Speakers
(d)
Logic Unit
(e)
Main Memory.
109.
is a symbol for
(a)
OR
(b)
XOR
(c)
AND
(d)
NAND
(e)
NOR.
110.
What is the operation sets to 1 the bits in one register where there are corresponding 1’s in the second register?
(a)
Selective Complement
(b)
Selective Clear
(c)
Selective Set
(d)
Mask
(e)
Insert.


Answers


101.
Answer :       (d)
Reason:  ROM is  the memory usually written by the manufacturer.
102.
Answer :       (e)
Reason:  D stands in D-flip flop stands for Data.
103.
Answer :       (b)
Reason:  The program is executed from main memory until it attempts to reference a page that is still in auxiliary memory called Page Fault.
104.
Answer :       (c)
Reason:  DMA stands for Direct Memory Access.
105.
Answer :       (b)
Reason:  The symbol to represent a state in the state diagram is
106.
Answer :       (d)
Reason:  DR ← M [AR] is Memory Read.
107.
Answer :       (d)
Reason:  A computer has memory of 256k words of 32 bits each, 18 bits  are required to specify the address part.
108.
Answer :       (c)
Reason:  Speakers can be called as a peripheral.
109.
Answer :       (c)
Reason:  is a symbol for AND.
110.
Answer :       (c)
Reason:  Selective Set is the operation sets to 1 the bits in one register where there are corresponding 1’s in the second register.




Featured Post

Happy Diwali 2025: Best 100 Diwali Wishes, Quotes, Messages, WhatsApp Status, Imagesdiwali 2025 diwali date

Happy Diwali 2025: Best 100 Diwali Wishes, Quotes, Messages, WhatsApp Status, Images

advertisement

Advertisement

ADVERTISEMENT