0% found this document useful (0 votes)
12 views

java mcq -sem

The document consists of a series of multiple-choice questions related to Java programming concepts, including packages, interfaces, threads, exception handling, and graphics. It covers various topics such as the use of classes and methods, the characteristics of StringBuffer and StringBuilder, and the functionalities of the AWT library. Each question provides options for answers, testing knowledge on Java syntax and behavior.

Uploaded by

saradha.r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

java mcq -sem

The document consists of a series of multiple-choice questions related to Java programming concepts, including packages, interfaces, threads, exception handling, and graphics. It covers various topics such as the use of classes and methods, the characteristics of StringBuffer and StringBuilder, and the functionalities of the AWT library. Each question provides options for answers, testing knowledge on Java syntax and behavior.

Uploaded by

saradha.r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

31.

An _______________ statement can be used to access the classes and interface of a


different package from the current package.

A. instanceOf
B. import
C. extends
D. implement

32. Which of the following packages is used to includes classes to create user interface like
Button and Checkbox?

A. java.lang
B. java.net
C. java.awt
D. java.io

33. Package in Java is a mechanism to encapsulate a ______________.

A. Classes
B. Sub Packages
C. Interfaces
D. All of the above

34. Which of the following is/are true about packages in Java?


1) Every class is part of some package.
2) All classes in a file are part of the same package.
3) If no package is specified, the classes in the file go into a special unnamed package
4) If no package is specified, a new package is created with folder name of class and the
class is put in this package.

35. Which of the following is/are advantages of packages?


A Packages avoid name clashes
B Classes, even though they are visible outside their package, can have fields visible to
packages only
C We can have hidden classes that are used by the packages, but not visible outside.
D All of the above
36. Which of these access specifiers can be used for an interface?

A. Public
B. private
C. Protected
D. All of the mentioned

37. Which of the following is a correct interface?


A. abstract interface A { abstract void print(); { }}
B. abstract interface A { print(); }
C. interface A { void print() { } }
D. interface A { void print(); }

38. Which of these keywords is used by a class to use an already defined interface?
a) import
b) import
C) tools
d) Implements

39 Which of these is valid about threads in java

a.Thread behaviour is unpredictable


b.execution of Threads depends on Thread scheduler
c.Same threading program may produce different output in subsequent executions even on
same platform
d.All

40. which of the following is true about methods in an interface in java?


A. An interface can contain only abstract method.
B. We can define a method in an interface
C. Private and protected access modifiers can also be used to declare methods in
interface
D. None

41. Output of following Java program?


class Main {
public static void main(String args[]) {
int x = 0;
int y = 10;
int z = y/x;
}
}

A. Compiler Error
B. Compiles and runs fine
C. Compiles fine but throws ArithmeticException exception
D. NONE

42. What is difference between starting thread with run() and start() method?
a.There is no difference
b.When you call start() method, main thread internally calls run() method to start newly
created Thread
c.run() calls start() method internally
d.None

43. Exception is a class/interface/abstract class/other?

a.Class
b.Interface
c.Abstract class
d.Other

44. What block is always executed, independently of a exception being raised?

a.throws
b.finally
c.catch
d.throw

45. How can Thread go from waiting to runnable state?

a.notify/notifAll
b.When sleep time is up
c.Using resume() method when thread was suspended
d.All
--------------------------------------------------------------------------------
46. The InputStream class defines methods for performing input functions such as
i) reading bytes ii) closing streams
iii) skipping ahead in a stream iv) flushing streams
A) ii, iii and iv only
B) i, ii and iii only
C) i, iii and iv only
D) All i, ii, iii and iv

47. Which of the following method(s) not included in InputStream class.


A) available( )
B) reset( )
C) flush( )
D) close( )

48. The method …………………., force writes whenever the data accumulates in the
output stream.
A) write( )
B) flush( )
C) read( )
D) reset( )

49. The ……………………… method of the BufferedReader class is used for reading
lines of text from the console, the file or other input streams.
A) read( )
B) read(byte[]b)
C) readLine( )
D) readByte( )

50. The ……………………. class implements the DataInput and DataOutput interfaces
for performing I/O using the primitive data types.
A) RandomAccessFile
B) OutputStream Reader
C) InputStreamReader
D) DataOutputStream

51. If you want to assign a value of 88 to the variable year, then which of the
following lines can be used within an <applet> tag.
A) number = getParameter(88)
B) <number=99>
C) <param = radius value=88>
D) <param name=number value=88>

52. The graphics class provides methods to draw a number of graphical figure
including
i) Text ii) Lines iii) Images iv) Ellipse
A) i, ii and iii only
B) ii, iii and iv only
C) i, iii and iv only
D) All i, ii, iii and iv

53. The ………………. method is defined by the AWT which causes the AWT runtime
system to execute a call to your applet’s update( ) method.
A) update( )
B) paint( )
C) repaint( )
D) reupdate( )

54. We can change the text to be displayed by an applet by supplying new text to be
displayed by an applet by supplying new text to the applet through a
……………………… tag.
A) <EDIT>
B) <CHANGE>
C) <REPLACE>
D) <PARAM>
55. Applet class is a subclass of the panel class, which is again a subclass of the
………………….. class.
A) object
B) component
C) awt
D) container

56. Which of the following statements are True for StringBuffer


and StringBuilder?

A. StringBuilder is not thread-safe.


B. StringBuffer is thread safe because its methods are synchronized.
C. StringBuilder was introduced in Java 1.4
D. StringBuffer and StringBuilder are immutable.

57. Select all the reasons that make String perfect candidate for
Map key?

A. String is immutable
B. String is final
C. String properly implements hashCode() and equals() method
C. All the above
58. Which of these class is used to create an object whose character sequence is
mutable?

 A. String()

 B. StringBuffer()

 C. Both of the mentioned

 D. None of the mentioned

59. What is the string contained in s after following lines of code?


StringBuffer s new StringBuffer(“Hello”);
s.deleteCharAt(0);

 A. Hell

 B. ello

 C. Hel

 D. llo

60. Which of the following statement is correct?

 A. replace() method replaces all occurrences of one character in invoking


string with another character.

 B. replace() method replaces only first occurances of a character in invoking


string with another character.

 C. replace() method replaces all the characters in invoking string with another
character.

 D. replace() replace() method replaces last occurrence of a character in


invoking string with another character.

--------------------------------------------------------------------------------------------------

61. In Graphics class which method is used to draws a rectangle with the specified
width and height?

 A. public void drawRect(int x, int y, int width, int) height

 B. public abstract void fillRect(int x, int y, int width, int height)

 C. public abstract void drawLine(int x1, int y1, int x2, int y2)

 D. public abstract void drawOval(int x, int y, int width, int height)


62. Name the class used to represent a GUI application window, which is optionally
resizable and can have a title bar, an icon, and menus.

 A. Window

 B. Panel

 C. Dialog

 D. Frame

63. What are the different types of controls in AWT?

 A. Labels

 B. Pushbuttons

 C. Checkboxes

 d All of these

64. Where are the following four methods commonly used?

1) public void add(Component c)


2) public void setSize(int width,int height)
3) public void setLayout(LayoutManager m)
4) public void setVisible(boolean)
- Published on 19 Oct 15

a. Graphics class
b. Component class
c. Both A & B
d. None of the above
65. Which is the container that doesn't contain title bar and MenuBars but it can have
other components like button, textfield etc?

Window
b. Frame
c. Panel
d. Container
66. Give the abbreviation of AWT?

Applet Windowing Toolkit


b. Abstract Windowing Toolkit
c. Absolute Windowing Toolkit
d. None of the above
67.
Which method is used to set the graphics current color to the specified color in the
graphics class?

public abstract void setFont(Font font)


b. public abstract void setColor(Color c)
c. public abstract void drawString(String str, int x, int y)
d. None of the above
68. Which object can be constructed to show any number of choices in the visible
window?

Labels
b. Choice
c. List
d. Checkbox

69. Which of the following are passed as an argument to the paint( ) method?
A Canvas object
A Graphics object
An Image object
A paint object

70 Which constructor creates a TextArea with 10 rows and 20 columns?


new TextArea(10, 20)
new TextArea(20, 10)
new TextArea(new Rows(10), new columns(20))
new TextArea(200)

71. Which method will cause a Frame to be displayed?


show( )
setVisible( )
display( )
displayFrame( )

72 ) 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

73. Which of the following statements are true?


a)The default layout manager for an Applet is FlowLayout
b) The default layout manager for an application is FlowLayout
c) A layout manager must be assigned to an Applet before the setSize method is
called
d) The Layout manager attempts to honor the preferred size of any components

74. Which colour is used to indicate instance methods in the standard "javadoc"
format documentation:
1) blue
2) red
3) purple
4) orange
75. What is the correct ordering for the import, class and package declarations when
found in a single file?
1) package, import, class
2) class, import, package
3) import, package, class
4) package, class, import

You might also like