Name - Hrythm R.No. - 1815689: Java MCQ Test - 25ques Coding Questions-2
Name - Hrythm R.No. - 1815689: Java MCQ Test - 25ques Coding Questions-2
R.No. -1815689
Question1.
Answer : a
Question 2.
int i = 0;
i = i++ + i;
Answer : b
Question 3.
(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.
Answer : b
Question 4.
(a) static (b) const (c) final (d) abstract (e) none of the above.
Answer : c
Question5.
(d) A class must be qualified as ‘abstract’ class, if it contains one abstract method.
Answer : c
Question 6.
Answer : d
Question.7.
static int i = 1;
System.out.println(i+” , “);
m(i);
System.out.println(i);
i += 2;
Answer : c
Question 8.
(b) A class which is implementing an interface must implement all the methods of the
interface.
(c) An interface can implement another interface.
Answer : c
Question 9.
(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.
Answer : c
Question 10.
public Test()
System.out.printf("1");
new Test(10);
System.out.printf("5");
System.out.printf("2");
System.out.printf("3");
a) 12345
b) Compilation error
c) 15
d) Runtime error
Answer : a
Question 11.
System.out.println("Run");
}
} class Myclass {
public
t.start();
System.out.println("Main");
Options:
1. Main Run
2. Run Main
Answer : 4
Question 12.
import java.io.IOException;
class Derived
System.out.println("Derived class");
}
public class Test extends Derived
System.out.println("Test class");
obj.getDetails();
Answer : b
Question 13.
str = null;
// calling garbage collector
System.gc();
Thread.sleep(1000);
System.out.println("end of main");
@Override
c) Compiler error
d) End main
Answer : d
Question 14.
System.out.println(obj.getSum());
a) 15
b) 9
c) 5
d) Compilation Error
Answer : d
Question 15.
class Test1 {
int x = 10;
{
System.out.println(x);
static
Option
A) 10 10
B) Error
C) Exception
D) none
Answer : b
import java.util.ArrayList;
class Demo {
System.out.print(list.get(0));
demo.show();
}
A. ArrayIndexOutOfBoundException
B. IndexOutOfBoundException
C. null
Answer : b
Question 17.
[A] one
[B] two
[C] three
[D] four
Answer : d
Question 18.
[A] PreparedStatement
[B] ParameterizedStatement
Answer : a
Question 19.
[A] UNIQUE
[B] SEQUENCE
[C] AUTO_INCREMENT
[D] None of the above -- Surrogate keys are not implemented in MySQL.
Answer : c
class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A ();
A obj2 = new A ();
System.out.print (obj1.equals (obj2));
}
}
a) false
b) true
c) 1
d) Compilation Error
Answer : a
Question 21.What will happen when you attempt to compile and run the following code?
package test;
Question 22.
What will be the output of following code?
Question 23.
package test;
importjava.io.*;
public class MyObjectFileStore
{
Public void storeObject(Employee emp)
{
OutputStream ops = null;
ObjectOutputStreamobjOps = null;
try {
ops = newFileOutputStream("MyEmpFile.txt");
objOps = newObjectOutputStream(ops);
objOps.writeObject(emp);
objOps.flush();
} catch (Exception e) {
e.printStackTrace();
}
InputStreamfileIs = null;
ObjectInputStreamobjIs = null;
try {
fileIs = newFileInputStream("MyEmpFile.txt");
objIs = newObjectInputStream(fileIs);
Employee emp = (Employee) objIs.readObject();
System.out.println(emp);
} catch (Exception e) {
e.printStackTrace();
Class Employee {
publicintgetId() {
return id;
}
publicvoidsetId(int id) {
this.id = id;
}
publicvoidsetSalary(String salary) {
this.salary = salary;
}
}
Answer : a
Question 24.
a) At most 1
b) At least 1
Answer : d
Question 25.
If two classes combine some private data members and provides public member functions to
access and manipulate those data members. Where is abstraction used?
B) Using class concept with both data members and member functions
C) Using public member functions to access and manipulate the data member
Answer : c