Info city. يتم التشغيل بواسطة Blogger.

MCQ on Java Programming With Answers set-11


1. If m and n are int type variables, what will be the result of the expression m%n when m=-14 and n=-3?

A) 4

B) 2

C) -2

D) -4



2. Consider the following code

if(number>=0)

if(number>0)

system.out.println("Number is positive");

else

system.out.println("Number is negative");

What will be the output if number is equal to 0?

A) Number is negative

B) Number is positive

C) Both A and B

D) None of the above



3. Consider the following code:

char c='a';

switch (c)

{
case 'a';

system.out.println("A");

case 'b';

system.out.println("B");

default;



system.out.println("C");
}

For this code, which of the following statement is true?

A) Output will be A

B) Output will be A followed by B

C) Output will be A, followed by B, and then followed by C

D) Code is illegal and therefore will not compile



4. Consider the following class definition.

class Student extends String

{
}

What happens when we try to compile this class?


A) Will not compile because class body is not defined

B) Will not compile because the class in not declared public.

C) Will not compile because string is abstract.

D) Will not compile because string is final.



5. What is wrong in the following class definitions?

abstract class print

{
abstract show();
}
class Display extends Print
{
}

A) Nothing is wrong

B) Wrong. Method show() should have a return type

C) Wrong. Method show() is not implemented in Display

D) Wrong. Display does not contain any numbers.



6. What is the error in the following class definitions?

abstract class XY
{
abstract sum(int x, int y){ }
}

A) Class header is not defined properly

B) Constructor is not defined

C) Method is not defined properly

D) No error.




7. Which of the following statements are true?

i) We cannot use abstract classes to instantiate objects directly.

ii) The abstract methods of an abstract class must be defined in its subclass.

iii) We cannot declare abstract constructors.

iv) We may declare abstract static methods.

A) Line i only

B) Line ii only

C) Line i and ii only

D) Line i, ii and iii only




8. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would archive this?

A) Private

B) Protected

C) Public

D) Private Protected




9. The use of protected keyword to a member in a class will restrict its visibility as follows:

A) Visible only in the class and its subclass in the same package.

B) Visible only inside the same package.

C) Visible in all classes in the same package and subclasses in other packages

D) Visible only in the class where it is declared.




10. Consider the following code:

interface Area
{
float compute (float x, float y);
}
class Room implements Area
{
float compute (float x, float y)

{
return(x&y);
}
}

What is wrong with the code?

A) Interface definition is incomplete

B) Method compute() in interface Area should be declared public

C) Method compute() in class Room should be declared public

D) All the above






Answers:



1. If m and n are int type variables, what will be the result of the expression m%n when m=-14 and n=-3?

C) -2


2. Consider the following code

if(number>=0)
if(number>0)
system.out.println("Number is positive");
else
system.out.println("Number is negative");

What will be the output if number is equal to 0?

A) Number is negative


3. Consider the following code:

char c='a';
switch (c)
{
case 'a';
system.out.println("A");
case 'b';
system.out.println("B");
default;
system.out.println("C");
}

For this code, which of the following statement is true?

B) Output will be A followed by B


4. Consider the following class definition.

class Student extends String
{
}

What happens when we try to compile this class?

D) Will not compile because string is final.


5. What is wrong in the following class definitions?

abstract class print
{
abstract show();
}
class Display extends Print
{
}

C) Wrong. Method show() is not implemented in Display


6. What is the error in the following class definitions?

abstract class XY
{
abstract sum(int x, int y){ }
}


C) Method is not defined properly


7. Which of the following statements are true?

i) We cannot use abstract classes to instantiate objects directly.

ii) The abstract methods of an abstract class must be defined in its subclass.

iii) We cannot declare abstract constructors.

iv) We may declare abstract static methods.

D) Line i, ii and iii only


8. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would archive this?

D) Private Protected


9. The use of protected keyword to a member in a class will restrict its visibility as follows:

C) Visible in all classes in the same package and subclasses in other packages


10. Consider the following code:

interface Area
{
float compute (float x, float y);
}
class Room implements Area
{
float compute (float x, float y)
{
return(x&y);
}
}

What is wrong with the code?

C) Method compute() in class Room should be declared public




Related Posts



For other more Multiple Choice Questions (MCQs): Click Here

0 التعليقات