250
100.4k

610+ Java Programming Solved MCQs

These multiple-choice questions (MCQs) are designed to enhance your knowledge and understanding in the following areas: Bachelor of Computer Applications (BCA) , Bachelor of Science in Computer Science (BSc CS) , Master of Computer Applications (MCA) , Programming Languages .

501.

Given the code String s = new String("abc"); Which of the following call is not valid?

A. s.trim().
B. s.replace('a', 'A').
C. s.substring (3).
D. s.setCharAt (1,'A').
Answer» B. s.replace('a', 'A').
502.

The methods wait() and notify() are defined in?

A. java.lang.String.
B. java.lang.Object.
C. java.lang.Runnable.
D. java.lang.Thread.
Answer» B. java.lang.Object.
503.

Given the following code:~~~class Base { int x = 10; }~~~class Derived extends Base~~~{ int x = 20; }~~~Base b = new Base();~~~Derived d = new Derived ( );~~~Base bd = new Derived(); The statement~~~System.out.println(b.x + " " + d.x + " " + bd.x);~~~will produce the output

A. 10 20 20.
B. 20 10 20.
C. 20 20 10.
D. 10 20 10.
Answer» D. 10 20 10.
504.

When we implement the Runnable interface, we must define the method

A. run().
B. start().
C. init().
D. main().
Answer» A. run().
505.

15 & 29 =?

A. 44.
B. 14.
C. 13.
D. 12.
Answer» C. 13.
506.

Identify the statements that are not correct:

A. Int a = 13, a>>2 = 3.
B. Int b = -8, b>>1 = -4.
C. Int a = 13, a>>>2 = 3.
D. Int b = -8, b>>>1 = -2.
Answer» B. Int b = -8, b>>1 = -4.
507.

Consider the following code: int x, y, z;~~~y = 1;~~~z = 5;~~~x = 0 - (++y) + z++;~~~after execution of this, what will be the values of x, y and z?

A. x = 4, y = 1, z = 5.
B. x = 3, y = 2, z = 6.
C. x = -7, y = 1, z = 5.
D. x = 4, y = 2, z = 6.
Answer» B. x = 3, y = 2, z = 6.
508.

What will be the result of the expression: a % b when a & b is of type int and their values~~~are a = 10 and b = 6?

A. 1.66.
B. 1.
C. 2.
D. 4.
Answer» D. 4.
509.

Which of the following statements about abstract methods/classes in JAVA is true?

A. An abstract class cannot be instantiated.
B. Constructors can be abstract..
C. A subclass of an abstract class must defined the abstract methods..
D. Static methods may be declared abstract.
Answer» A. An abstract class cannot be instantiated.
510.

The keywords reserved but used in the initial version of JAVA are:

A. union.
B. const.
C. inner.
D. goto.
Answer» A. union.
511.

When we invoke repaint() for a JAVA.awt.Component object, the AWT invokes the method _____________.

A. update().
B. draw().
C. show().
D. paint().
Answer» A. update().
512.

The setBackground() method is part of the following class in JAVA.awt package.

A. Component.
B. Graphics.
C. Applet.
D. Container.
Answer» A. Component.
513.

Which of the following methods can be used to draw the outline of a square within a JAVA.awt.Component object?

A. drawLine().
B. fillRect().
C. drawString().
D. drawPolygon().
Answer» A. drawLine().
514.

DataInput is ________________.

A. an interface that defines methods to read primitive data types.
B. an abstract class defined in java.io.
C. a class we can use to read primitive data types.
D. an interface that defines methods to open files.
Answer» A. an interface that defines methods to read primitive data types.
515.

Which of the following method can be used to change the size of a JAVA.awt.Component object?

A. dimension().
B. setSize().
C. area().
D. size().
Answer» B. setSize().
516.

What method is used to specify a container's layout?

A. setLayout().
B. setSize().
C. area().
D. resize().
Answer» A. setLayout().
517.

27 | 8 = ?

A. 8.
B. 27.
C. 19.
D. 35.
Answer» B. 27.
518.

What will be the result of the expression : a % b~~~when a and b are of type int and their values are a = -17 and b = -6?

A. -5.
B. -23.
C. 0.
D. 5.
Answer» D. 5.
519.

Choose the operations that can be performed on String objects:

A. +=.
B. -.
C. %.
D. ^.
Answer» A. +=.
520.

(1 | 4) + (4 & 2) = ?(in base ten)

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

Given the declarations~~~boolean b;~~~short x1 = 100, x2 = 200, x3 = 300; Which of the following statement is evaluated to true?

A. b = x1 * 2 == x2;
B. b = x1 + x2 != 3 * x1;
C. b = (x3 - 2*x2<0) && ((x3 = 400)<2**x2);
D. b = (x3 - 2*x2>0) || ((x3 = 400) 2*x2);
Answer» A. b = x1 * 2 == x2;
522.

Which of the following represent legal flow control statements?

A. break;
B. break();
C. continue(inner);
D. exit();
Answer» A. break;
523.

A class can be converted to a thread by implementing the interface ____________.

A. Thread.
B. Runnable.
C. Start.
D. Yield.
Answer» B. Runnable.
524.

Which Control Statements allow the program to choose different paths of execution?

A. none of the below
B. if-else.
C. selection.
D. for.
Answer» C. selection.
525.

________ are stored in hierarchical manner.

A. packages.
B. interfaces.
C. classes.
D. Threads.
Answer» A. packages.
526.

After the following code fragment, what is the value in a?~~~String s; int a;~~~s = "Foolish boy."; a = s.indexOf("fool");

A. -1.
B. 0.
C. 4.
D. random value.
Answer» A. -1.
527.

What is an infinite loop?

A. A loop that functions infinitely well.
B. A loop that runs forever.
C. A loop that never starts.
D. A loop that will never function.
Answer» B. A loop that runs forever.
528.

What is the difference between a TextArea and a TextField?

A. A TextArea can handle multiple lines of text.
B. A textarea can be used for output.
C. TextArea is not a class.
D. TextAreas are used for displaying graphics.
Answer» A. A TextArea can handle multiple lines of text.
529.

What is the purpose of this bit of code?~~~void init()~~~{~~~}

A. A class that initializes the applet.
B. A required method in an applet.
C. A place to declare variables.
D. Interacting with the user.
Answer» B. A required method in an applet.
530.

A compound statement is ________.

A. A collection of one or more statements enclosed in braces.
B. A statement involving if and else.
C. A way of declaring variables.
D. A way of setting the value of a variable.
Answer» A. A collection of one or more statements enclosed in braces.
531.

Which of the following is NOT an example of a data type?

A. int.
B. public.
C. Button.
D. void.
Answer» B. public.
532.

The following is an example of a boolean expression

A. x = 6.
B. m1.setText("Hello.").
C. cause == bYes.
D. 70.
Answer» C. cause == bYes.
533.

A function is: _________________.

A. An entity that receives inputs and outputs.
B. A way of storing values.
C. A sequence of characters enclosed by quotes.
D. A kind of computer.
Answer» A. An entity that receives inputs and outputs.
534.

The data type for numbers such as 3.14159 is _________.

A. double.
B. int.
C. real.
D. String.
Answer» A. double.
535.

Given the following statement: huey.setDouble(8.0*32.2+1.0);~~~What must be the data type of huey?.

A. DoubleField.
B. TextField.
C. intField.
D. double.
Answer» A. DoubleField.
536.

Given the following code fragment:~~~int A[];int i = 0;A = new int A[4];~~~while (i < 4)~~~{~~~A[i] = 10;~~~i = i + 1;~~~}~~~What is the value of A[3]?.

A. 0.
B. 3.
C. 10.
D. 9.
Answer» C. 10.
537.

What is the value of k after the following code fragment?~~~int k = 0;~~~int n = 12~~~while (k < n)~~~{~~~k = k + 1;~~~}

A. 0.
B. 11.
C. 12.
D. 10.
Answer» C. 12.
538.

When an instance of a class, or object, is specified as a parameter to a method, ______ to the said object is passed to the method.

A. a reference.
B. formal parameter.
C. references.
D. actual parameter.
Answer» A. a reference.
539.

The modulus operator (%) in JAVA can be used only with variables of ______ type.

A. double & char.
B. int & double.
C. int.
D. double.
Answer» B. int & double.
540.

An array of objects, which may have_______ type of different classes.

A. different.
B. same.
C. mixed mode.
D. common.
Answer» A. different.
541.

Which of the following statement is false?

A. The sleep() method should be enclosed in try ... catch block.
B. The yield() method should be enclosed in try ... catch block.
C. A thread can be temporarily suspended from running by using the wait() method.
D. A suspended thread using suspend() method can be revived using the resume() method.
Answer» B. The yield() method should be enclosed in try ... catch block.
542.

When Java source code is compiled, each individual class is put into its own output file named after the class and using the ______ extension.

A. .h.
B. . java.
C. >java.
D. .class.
Answer» D. .class.
543.

Java was conceived by __________.

A. microsoft.
B. oracle.
C. sun microsystem.
D. intel.
Answer» C. sun microsystem.
544.

An _________ is a special kind of Java program that is designed to be transmitted over the internet.

A. viewlet.
B. applet.
C. servlet.
D. object.
Answer» B. applet.
545.

When you read your e-mail, you are viewing _________ data.

A. active.
B. passive.
C. active and passive.
D. active or passive.
Answer» B. passive.
546.

There are ________ types of comments in Java.

A. one.
B. two.
C. three.
D. four.
Answer» D. four.
547.

Java enables the creation of cross-platform programs by compiling into an intermediate representation called Java ____________.

A. byte code.
B. firewall.
C. tetra code.
D. view code.
Answer» A. byte code.
548.

What class is the top of the AWT event hierarchy?

A. iostream class
B. java.awt.AWTEvent class
C. io.awt.AWTEvent class
D. java.Event class
Answer» B. java.awt.AWTEvent class
549.

What does J2SE mean?

A. Java 2 Platform Standard Edition.
B. Java 2 Internet Standard Edition.
C. Java 2 Platform Independent Standard Edition.
D. Java 2 Systems Edition.
Answer» A. Java 2 Platform Standard Edition.
550.

Java support RMI. What does this RMI stands for?

A. Random Memory Interface.
B. Remote Method Invocation.
C. Random Method Invocation.
D. Remote Memory Interface.
Answer» B. Remote Method Invocation.

Done Studing? Take A Test.

Great job completing your study session! Now it's time to put your knowledge to the test. Challenge yourself, see how much you've learned, and identify areas for improvement. Don’t worry, this is all part of the journey to mastery. Ready for the next step? Take a quiz to solidify what you've just studied.