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 .

451.

Which of these data tupe can be used for a method having a return statement in it?.

A. void.
B. int.
C. float.
D. All of the mentioned.
Answer» D. All of the mentioned.
452.

What is an example of polymorphism?

A. inner class.
B. anonymous classes.
C. method overloading.
D. method overriding.
Answer» C. method overloading.
453.

An interface contains __________ methods.

A. non-abstract.
B. implemented.
C. unimplemented.
D. abstract.
Answer» C. unimplemented.
454.

Which of the following is not a wrapper class?

A. string.
B. integer.
C. boolean.
D. character.
Answer» A. string.
455.

Which of these is the method which is executed first before execution of any other thing takes place in a program?.

A. main method.
B. finalize method.
C. static method.
D. private method.
Answer» C. static method.
456.

Which of the following methods are methods of the String class?

A. delete( ).
B. append( ).
C. reverse( ).
D. replace( ).
Answer» D. replace( ).
457.

If you run the code below, what gets printed out?String s=new String ("Bicycle"); int iBegin=1; char iEnd=3; System.out.println (s.substring (iBegin, iEnd));

A. Bic.
B. ic.
C. icy.
D. error: no method matching substring(int, char).
Answer» B. ic.
458.

Given the following declarations String s1=new String("Hello") ; String s2=new String("there"); String s3=new String(); Which of the following are legal operations?

A. s3=s1 + s2;.
B. s3=s1 - s2;.
C. s3=s1 & s2.
D. s3=s1 && s2.
Answer» A. s3=s1 + s2;.
459.

Which of the following classes is used to perform basic console I/O?

A. system.
B. security Manager.
C. math.
D. runtime.
Answer» A. system.
460.

Which of these keywords is used to define packages in Java?,

A. pkg
B. Pkg.
C. package.
D. Package.
Answer» C. package.
461.

Which of the following are true about the Error and Exception classes?

A. Both classes extend Throwable.
B. The Error class is final and the Exception class is not.
C. The Exception class is final and the Error is not.
D. Both classes implement Throwable.
Answer» A. Both classes extend Throwable.
462.

Which of the following are true?

A. The Void class extends the Class class.
B. The Float class extends the Double class.
C. The System class extends the Runtime class.
D. The Integer class extends the Number class.
Answer» D. The Integer class extends the Number class.
463.

Which of the following will output -4.0?

A. System.out.println(Math.floor(-4.7));.
B. System.out.println(Math.round(-4.7));.
C. System.out.println(Math.ceil(-4.7));.
D. System.out.println(Math.Min(-4.7));.
Answer» C. System.out.println(Math.ceil(-4.7));.
464.

What is the default return type to main() __________.

A. void.
B. double.
C. float.
D. int.
Answer» D. int.
465.

Which of the following statements are true?

A. UTF characters are all 8-bits.
B. UTF characters are all 16-bits.
C. UTF characters are all 24-bits.
D. Unicode characters are all 16-bits.
Answer» D. Unicode characters are all 16-bits.
466.

You execute the code below in an empty directory. What is the result? File f1 = new File ("dirname");F ile f2 = new File (f1, "filename");

A. A new directory called dirname is created in the current working directory.
B. A new directory called dirname is created in the current working directory.
C. A new file called filename is created in the current working directory.
D. No directory is created, and no file is created.
Answer» C. A new file called filename is created in the current working directory.
467.

How do you create a Reader object from an InputStream object?

A. Use the static createReader( ) method of InputStream class.
B. Use the static createReader( ) method of Reader class.
C. Create an InputStreamReader object, passing the InputStream object as an argument to the InputStreamReader constructor.
D. Create an OutputStreamReader object, passing the InputStream object as an argument to the OutputStreamReader constructor.
Answer» C. Create an InputStreamReader object, passing the InputStream object as an argument to the InputStreamReader constructor.
468.

How can you change the current working directory using an instance of the File class called FileName?

A. FileName.chdir("DirName").
B. FileName.cd("DirName").
C. FileName.cwd("DirName").
D. The File class does not support directly changing the current directory.
Answer» D. The File class does not support directly changing the current directory.
469.

Which of these is a mechanism for naming and visibility control of a class and its content?.

A. Object.
B. Packages.
C. Interfaces.
D. None of the Mentioned.
Answer» B. Packages.
470.

Which of the following is correct way of importing an entire package named as pkg?.

A. import pkg.
B. Import pkg.
C. import pkg.*.
D. Import pkg.*
Answer» C. import pkg.*.
471.

Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?.

A. super(void);.
B. superclass.();.
C. super.A();.
D. super();.
Answer» D. super();.
472.

Suppose A is an abstract class ,B is a concrete subclass of A, and both A and B have an default constructor. Which of the following is correct? a) A a = new A(); b)A a = new B(); c) B b = new A(); d) B b = new B();

A. Both a & b.
B. Both b & d.
C. Both b & c.
D. Both a & c.
Answer» B. Both b & d.
473.

Which of the following declares an abstract method in an abstract Java class?

A. public abstract method();.
B. public abstract void method();.
C. public void method(){ };.
D. private abstract void method(){ };.
Answer» B. public abstract void method();.
474.

Which of these keywords are used to define an abstract class?.

A. abst
B. abstract
C. Abstract
D. abstract class
Answer» B. abstract
475.

Which of these is not a correct statement?.

A. Every class containing abstract method must be declared abstract.
B. Abstract class defines only the structure of the class not its implementation.
C. Abstract class can be initiated by new operator.
D. Abstract class can be inherited.
Answer» C. Abstract class can be initiated by new operator.
476.

Which of the following statements about the try{} block in Java is false?

A. Some of the statements in a try{} block will never throw an exception.
B. The try{} block must appear before the catch{} blocks.
C. The try{} block cannot contain loops or branches.
D. The statements in a try{} block may throw several types of exception.
Answer» C. The try{} block cannot contain loops or branches.
477.

The concept of multiple inheritance is implemented in Java by ____ (i.) extending two or more classes (ii.) extending one class and implementing one or more interfaces (iii.) implementing two or more interfaces (iv.) all of these

A. (i), (ii), (iii) & (iv)
B. (i) only
C. (i) & (iii) only
D. (ii) & (iii) only
Answer» D. (ii) & (iii) only
478.

What is polymorphism in Java? .

A. It is when a single super class has many subclasses.
B. It is when a single variable is used with several different types of related objects.
C. It is when a program uses several different types of objects, each with its own variable.
D. It is when a class has several methods with the same name but different parameter types.
Answer» D. It is when a class has several methods with the same name but different parameter types.
479.

What code would you use to construct a 24-point bold serif font?

A. new Font (Font. SERIF, 24,Font.BOLD);.
B. new Font("SERIF", Font.BOLD,24);.
C. new Font("BOLD ", 24,Font.SERIF);.
D. new Font (Font. SERIF, "BOLD", 24);.
Answer» B. new Font("SERIF", Font.BOLD,24);.
480.

A / An ________ variable is shared by all instances of the class. It exists even before an object is created.

A. instance
B. abstract
C. interface
D. static
Answer» A. instance
481.

The concept of derived classes is involved in _________.

A. encapsulation.
B. information hiding.
C. polymorphism.
D. inheritance.
Answer» C. polymorphism.
482.

Which of these keywords is used by a class to use an interface defined previously?.

A. import.
B. imports.
C. implements.
D. implement.
Answer» C. implements.
483.

super keyword can be used to _____.

A. call super class constructor.
B. access super class member
C. both a and b.
D. none of the above
Answer» C. both a and b.
484.

Overloaded methods ___.

A. are a group of methods with the same name.
B. have the same number and type of arguments.
C. make life simpler for programmer.
D. may fail unexpectedly due to stress.
Answer» A. are a group of methods with the same name.
485.

____ are automatically called when an object is destroyed.

A. collectGarbage().
B. Destructor().
C. finalize().
D. final().
Answer» C. finalize().
486.

___ keyword is used to refer to the current object.

A. super.
B. this.
C. new.
D. volatile.
Answer» B. this.
487.

When a class is declared as final , then ____.

A. It can not be inherited
B. It must be inherited
C. Its object can not be created
D. none of these
Answer» A. It can not be inherited
488.

When method is overridden , then by subclass object which class method is called _____.

A. super class.
B. subclass.
C. both.
D. none
Answer» A. super class.
489.

Before doing garbage collection , _____ method is called .

A. main().
B. finalize().
C. final().
D. collect().
Answer» B. finalize().
490.

The .dot operator connects the following two entities _____.

A. a class member and a class object
B. a class object and a class
C. a class and a member of that class.
D. a class object and a member of that class.
Answer» A. a class member and a class object
491.

Which layout should you use to organize the components of a container in a tabular~~~form?

A. Card Layout.
B. BorederLayout.
C. Flow Layout.
D. Grid Layout.
Answer» D. Grid Layout.
492.

An Applet has its Layout Manager set to the default of FlowLayout. What code~~~would be the correct to change to another Layout Manager?

A. setLayoutManager(new GridLayout());.
B. setLayout(new GridLayout(2,2));.
C. setGridLayout(2,2,)).
D. setBorderLayout();.
Answer» B. setLayout(new GridLayout(2,2));.
493.

How do you indicate where a component will be positioned using Flowlayout?

A. North, South, East, West.
B. Assign a row/column grid reference.
C. Pass a X/Y percentage parameter to the add method.
D. Do nothing, the FlowLayout will position the component.
Answer» D. Do nothing, the FlowLayout will position the component.
494.

How do you change the current layout manager for a container?

A. Use the setLayout method.
B. Once created you cannot change the current layout manager of a component.
C. Use the setLayoutManager method.
D. Use the updateLayout method.
Answer» A. Use the setLayout method.
495.

Which of the following may contain a menu bar?

A. A panel.
B. A frame.
C. An applet.
D. A menu bar.
Answer» B. A frame.
496.

What will be the content of array variable table after executing the following code?

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (j == i) {
table[i][j] = 1;
} else {
table[i][j] = 0;
}
}
}

A. 0 0 0 0 0 0 0 0 0.
B. 1 0 0 1 1 0 1 1 1.
C. 1 0 0 0 1 0 0 0 1.
D. 0 0 1 0 1 0 1 0 0.
Answer» C. 1 0 0 0 1 0 0 0 1.
497.

Which of the following classes are not available in the java.lang package?

A. Stack.
B. Object.
C. Math.
D. String.
Answer» A. Stack.
498.

Which of the following are not the wrapper classes?

A. Byte.
B. Vector.
C. Integer.
D. Short.
Answer» C. Integer.
499.

Which of the following method is not belonging to the String class?

A. length().
B. reverse().
C. compareTo() .
D. equals().
Answer» B. reverse().
500.

If not assigned a value, a variable of type char has the following default value:

A. \uffff'.
B. \u0000'.
C. " " (space).
D. '\u0001'.
Answer» B. \u0000'.

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.