Java Basic, PREPARED BY PODMESWAR , ONLY FOR FAIR USE

 

1. Which of the following will produce a value of 22 if x=22.9:

(a) Ceil(x)

(b) Round(x)

(c) Rint(x)

(d) Abs(x)

Answer: (c) Rint(x)

 

 

2. 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

Answer: (c) -2

 

 

3. Consider the following statements:

int x = 10, y = 15;

x = ((x < y) ? (y + x) : (y - x);

What will be the value of x after executing these statements?

(a) 25

(b) 15

(c) 5

(d) Error can't be executed.

Answer: (a) 25

 

 

4. Which of the following will produce a value of 10 if x = 9.7?

(a) floor(x)

(b) abs(x)

(c) rint(x)

(d) round(x)

Answer: (d) round(x)

 

 

5. Which of the following control expressions are valid for an if statement?

(a) an integer expression

(b) a Boolean expression

(c) either A or B

(d) Neither A or B

Answer: (b) a Boolean expression

 

 

6. 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 class is not declared public

(c) Will compile successfully.

(d) Will not compile because String is abstract

Answer: (d) Will not compile because String is abstract

 

 

7. 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 Methods show() is not implemented in Display

(d) Wrong Display does not contain any members.

Answer: (c) Wrong Methods show() is not implemented in Display

 

 

8. What is error in the following class definitions?

abstract class xy {

abstract sum(int x, int y) {

}

}

(a) class header is not define properly

(b) constructor is no defined

(c) method is not defined properly

(d) no error

Answer: (c) method is not defined properly

 

 

9. Consider the following class definitions:

class maths {

student student1;

}

class student {

String name;

}

This code represents:

(a) an 'is a' relationship

(b) a 'has a' relationship

(c) both

(d) neither

Answer: (b) a 'has a' relationship

 

 

10. Which key word can protect a class in package from accessibility by the classes outside the package?

(a) private

(b) protected

(c) final

(d) don't use any keyword at all(make it default)

Answer: (d) don't use any keyword at all(make it default)

 

 

11. 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 achieve this?

(a) private

(b) protected

(c) public

(d) private protected

Answer: (d) private protected

 

 

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

(a) Visibility only in the class and its subclasses in the same package.

(b) Visibility only inside the same package.

(c) Visibility in all classes in the same package and subclasses in other packages.

(d) Visibility only in the class where it is declared.

Answer: (c) Visibility in all classes in the same package and subclasses in other packages.

 

 

13. Which of the following are not keywords?

(a) NULL

(b) Implements

(c) Protected

(d) None of the above

Answer: (a) NULL

 

 

14. Which of the following are keywords?

(a) integer

(b) default

(c) Boolean

(d) Object

Answer: (b) default

 

 

15. Which of the following keywords are used to control access to a class member?

(a) default

(b) protected

(c) interface

(d) None of the above

Answer: (b) protected

 

 

16. The keywords reserved but not used in the initial version of Java re:

(a) Synchronized

(b) Boolean

(c) union

(d) goto

Answer: (d) goto

 

 

17. A package is a collection of

(a) classes

(b) interface

(c) editing tools

(d) classes and interfaces

Answer: (d) classes and interfaces

 

 

18. Which of the following statements are true?

(a) An abstract class may not have any final methods?

(b) A final class may not have any abstracts methods.

(c) Transient variables must be static.

(d)  all of the above

Answer: (b) A final class may not have any abstracts methods.

 

 

19. The concept of multiple inheritance is implemented in Java by

(a) extending two or more classes

(b) extending one class and implementing one or more interfaces

(c) all the above

(d) None of the above

Answer: (b) extending one class and implementing one or more interfaces

 

 

20. Which of the following statements are valid array declarations?

(a) int number();

(b) float average[];

(c) double[] marks;

(d) counter int[];

Answer: (b) float average[];

 

 

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

(a) Random

(b) Stack

(c) String Buffer

(d) Vector

Answer: (a) Random

 

 

22. Which of the following are the wrapper classes?

(a) Random

(b) Vector

(c) Byte

(d) all of the above

Answer: (c) Byte

 

 

23. Which of the following methods belong to the String class?

(a) length()

(b) compareTo()

(c) substring()

(d) all of the them

Answer: (d) all of the them

 

 

24. Given the code

String s = new String("abc");

Which of the following calls are valid?

(a) s.toUpperCase()

(b) s.append("xyz")

(c) s.setCharAt(1<'A')

(d) all of the above

Answer: (a) s.toUpperCase()

 

 

25. The methods wait() and noify() are defined in

(a) java.lang.Thread

(b) java.lang.Runnable

(c) java.lang.Object

(d) java.lang.ThreadGroup

Answer: (c) java.lang.Object

 

 

26. When we invoke repaint () for a Component, the AWT invokes the method:

(a) draw()

(b) update()

(c) show()

(d) paint()

Answer: (b) update()

 

 

27. What does the following line of code do?

TextField text=new TextField(10);

(a) Creates text object that can hold 10 rows of text.

(b) Creates text object that can hold 10 columns of text.

(c) Creates the object text and initializes it with the value 10.

(d) The code is illegal.

Answer: (b) Creates text object that can hold 10 columns of text.

 

 

28. Which of the following methods can be used to draw the outline of a square?

(a) fillRect()

(b) drawLine()

(c) drawString()

(d) all of the above

Answer: (b) drawLine()

 

 

29. Which of the following methods can be used to change the size of a

size() *

resize()

(a) component

(b) dimension()

(c) setSize()

(d) size()

Answer: (c) setSize()

 

 

30. Which of the following methods can be used to remove a component from the display?

(a) remove()

(b) desappear()

(c) hide()

(d) move()

Answer: (c) hide()

 

 

No comments:

Post a Comment