November 27, 2019

Object Oriented Programming and Design - MCQS

Note: We have tried to upload as much as we can, all the question and answers might be shuffled - Please find the answer below each question, some answers might be wrong please review on the last date(some answers might be changed) if you find any wrong answer please comment down below.


Question: 1



Select one:
A. The program has a runtime error because the array elements are not initialized.
B. The program has a compile error because the size of the array wasn’t specified when declaring the array.
C. The program has a runtime error because the array element x[0] is not defined.
D. The program runs fine and displays x[0] is 0.
Correct Answer: The program runs fine and displays x[0] is 0.

Question: 2
Given:
public class Foo {
staticint[] a;
static { a[0]=2; }
public static void main( String[] args ) {}
 }
Which exception or error will be thrown when a
programmer attempts to run this code?
Select one:
A. Compilation fails
B. java.lang.StackOverflowError
C. java.lang.IllegalStateException
D. java.lang.ExceptionInInitializerError
E. java.lang.ArrayIndexOutOfBoundsException
Correct Answer: java.lang.ExceptionInInitializerError

Question: 3
For a given interface, which of the following can we legally declare within an interface definition?
Select one:
A. public double methoda();
B. protected void methoda(double d1);
C. static void methoda(double d1);
D. public final double methoda();
Correct Answer: protected void methoda(double d1);

Question: 4
Among given methods, which is executed first before execution of any other in a java program?
Select one:
A. args public method
B. static before main method
C. main in private method
D. main in public methods
Correct Answer: static before main method

Question: 5
What is the default value of a static integer variable of a class in java?
Select one:
A. 1
B. null
C. 0
D. Garbage value
Correct Answer: 0

Question: 6
Which of the following are the legal declarations of array?
Select one:
A. int () myScores (2);
B. int [] totalPrice ();
C. int [] myScores [];
D. int () myScores [2];
Correct Answer: int [] myScores [];

Question: 7
What is the output of the following code?
int y = 100, x = 5;
while(y > 0)
{
y--;
if(y%x != 0)
{
            continue;
}
System.out.println(y);
}
Select one:
A. Prints from 95 skipping 5
B. Error
C. Prints 1 to 100
D. None of the above
Correct Answer: Prints from 95 skipping 5

Question: 8
public class Test {
public void print(byte x) {
System.out.print("byte");
 }
public void print(Integer x) {
System.out.print("Integer");
 }
public void print(Short x) {
System.out.print("Short");
 }
public void print(Object x) {
System.out.print("Object");
 }
public static void main(String[] args) {
 Test t = new Test();
short s = 123;
t.print(s);
t.print(true);
t.print(6.789);
 }
}
Select one:
A. IntegerObjectObject
B. IntegerIntegerObject
C. ShortObjectObject
D. byteObjectObject
E. byteObjectObject
Correct Answer: ShortObjectObject

Question: 9
Given:
public class Test {
public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
if ((x == 4) && !b2 )
System.out.print("1 ");
System.out.print("2 ");
if ((b2 = true) && b1 )
System.out.print("3 ");
 }
 }
What is the result?
Select one:
A. 2
B. 1 2 3
C. 2 3
D. 1 2
E. 3
Correct Answer: 2 3

Question: 10
What will be the output of the following Java program, if attempted to compile and run this code with command line argument “java Account ragu raja”?
public class Account
{
  Static int rupee=18000;
public static void main(String arg[])
        {
int rupee=12000;
  System.out.println(arg[1]+" :Rs."+rupee);
        }
}
Select one:
A. Compilation and output raja :  Rs.12000
B. Compilation and output raja :  Rs.18000
C. Compile time error
D. Compilation and output ragu : Rs.12000
Correct Answer: Compile time error

Question: 11
class conversion
        {
        public static void main(String [] args)
        {
        double a = 295.04;
        int b = 300;
        byte c = (byte)a;
        byte d =(byte) b;
        System.out.println(c+ "  " + d);
        }
        }
Select one:
A. None of these
B. 39 43
C. 39 44
D. 295 300
E. 38 43
Correct Answer: 39 44

Question: 12
Which of the following is not an valid declaration of an array?
Select one:
A. int a[][]=new int[3][3];
B. int[] a=new int[3];
C. int [][]a=new int[][3];
D. int [][]a=new int[3][];
Correct Answer: int[] a=new int[3];
  
Question: 13
What Java keyword is used to declare a constant?
Select one:
A. Private
B. Static
C. None of the above
D. Final
Correct Answer: Final

Question: 14
Which of these is not a correct statement?
1.  Java support  Multilevel Inheritance
2.   Abstract class can be initiated by new operator
3.  Abstract class defines only the structure of the class not its implementation
4.  Abstract class cannot be inherited
Select one:
A. 2
B. 1 and 4
C. 1 and 2
D.1 and 3
Correct Answer: 1 and 2

Question: 15
In Java, int data type is
Select one:
A. Primitive Datatype with 16 bit size
B. Primitive Datatype with 32 bit size
C. Reference Datatype with 16 bit size
D. Reference Datatype with 32 bit size
Correct Answer: Primitive Datatype with 32 bit size

Question: 16
To prevent any method for overriding, we declare the method as
Select one:
A. final
B. Static
C. const
D. abstract
Correct Answer: final

Question: 17
Which of the following is not the reserved word in Java
Select one:
A. Char
B. Interfaces
C. String
D. Class
Correct Answer: String

Question: 18
When function overloading will not happen ?
Select one:
A. More than one method with same name, same signature, same number of parameters but different type
B. More than one method with same name but different method signature and different number or type of parameters
C. More than one method with same name, same signature but different number of signature
D. More than one method with same name, same number of parameters and type but different signature
Correct Answer: More than one method with same name, same signature but different number of signature

Question: 19
Which of the following line will not compile assuming x, y and z are bytes and j is int variable?
Select one:
A. z = 10 * x;
B. x = 3;
C. y = (byte)j;
D. z = a * b;
Correct Answer: z = 10 * x;

Question: 20

Select one:
A. 34
B. 34 S
C. S
D. Throws exception.
Correct Answer: 34 S

Question: 21
public class Test
{
public static void main (String[] args)
    {
        String foo = args[1];
        String bar = args[2];
        String baz = args[3];
System.out.println("baz = " + baz); /* Line 8 */
    }
}
Command line statement is as follows
java Test .class hello .exe epam
Select one:
A. Runtime Exception
B. baz = .
C. baz = null
D. baz = epam
Correct Answer: Runtime Exception

Question: 22
Which of the following is not true about super keyword
Select one:
A. Super never references to base class.
B. The super keyword is available in all non-static methods of a class.
C. Using super is the only case in which the type of the reference governs selection of the method implementation to be used
D. Super acts as a reference to the current object as an instance of its superclass
Correct Answer: Super never references to base class.

Question: 23
Given:
 23. Object [] myObjects = {
 24. new Integer(12),
 25. new String("foo"),
 26. new Integer(5),
 27. new Boolean(true)
 28. };
 29. Arrays.sort(myObjects);
 30. for(inti=0; i<myObjects.length; i++) {
 31. System.out.print(myObjects[i].toString());
 32. System.out.print(" ");
 33. }
What is the result?
Select one:
A. Compilation fails due to an error in line 23.
B. The value of all four objects prints in natural order.
C. A ClassCastException occurs in line 29.
D. Compilation fails due to an error in line 29.
E. A ClassCastException occurs in line 31.
Correct Answer: A ClassCastException occurs in line 29.

Question: 24
in Java, the range at which a char can span from
Select one:
A. -65535 to 65535
B. -32767 to 32766
C. 0 to 65535
D. -32768 to 32768
Correct Answer: 0 to 65535

Question: 25
Which of the following is correct?
Select one:
A. package Members declared with no access modifier are not accessible in any class at all.
B. package Members declared with private access modifier are accessible in classes in the other package, as well as in the same class itself.
C. package Members declared with private access modifier are accessible in classes in the same package, as well as in the class itself.
D. package Members declared with no access modifier are accessible in classes in the same package, as well as in the class itself.
Correct Answer: package Members declared with no access modifier are accessible in classes in the same package, as well as in the class itself.

Question: 26
Which of the following is not true about abstract class?
Select one:
A. Abstract class can contain variables marked with final keyword
B. An object of abstract class can always be created.
C. Abstract class can contain abstract and non-abstract methods
D. Each method not implemented in abstract class is also marked abstract
Correct Answer: An object of abstract class can always be created.

Question: 27
public static void main(String[] args){
               /*insert code here*/
        array[0]=10;
        array[1]=20;
        System.out.print(array[0]+":"+array[1]);
        }
 Which code fragment, when inserted at line 2, enables the code to print 10:20?

Select one:
A.
Integer array[]=new Integer[2];
               for(inti : array.length)
                       array[i]=new Integer();
B.
int[] array;
array =new  int[2];
C.int array = new int[2];
D.int array [2] ;
Correct Answer: B. int[] array;
array =new  int[2];

Question: 28
class X{
        static int i;
        int j;
        public static void main(String[] args){
               X x1= new X();
               X x2 = new X();
               x1.i=3;
               x1.j=4;
               x2.i=5;
               x2.j=6;
               System.out.println(x1.i + " "+ x1.j+ " "+x2.i+ " "+x2.j );
        }
}
What is the result?
Select one:
A. 3 4 3 6
B. 3 4 5 6
C. 3 6 4 6
D. 5 4 5 6
Correct Answer: 5 4 5 6

Question: 29
class Test {
public void display(int x, double y) {
System.out.println(x+y);
}
public double display(int p, double q){
return (p+q);
}
public static void main(String [] args) {
Test test = new Test();
test.display(4, 5.0);
System.out.println(test.display(4,5.0));
} }
Select one:
A. Compilation Error
B. 9.0 9.0
C. 9 9
D. None of these
Correct Answer: Compilation Error

Question: 30
Which of the following are true?
Select one:
A. A public class that has private fields and package private methods is not visible to classes outside the package.
B. Package private access is more lenient than protected access.
C.
You can use access modifiers to allow read access to all methods, but not any instance variables.
E. You can use access modifiers to restrict read access to all classes that begin with the word Test.
D.
You can use access modifiers so only some of the classes in a package see a particular package private class.
Correct Answer: You can use access modifiers to allow read access to all methods, but not any instance variables.

No comments:

Post a Comment