0

Java

Description: answering the questions need basic knowledge of methods in java
Number of Questions: 15
Created by:
Tags: Concept based questions Java/Oracle /C/C++
Attempted 0/15 Correct 0 Score 0

Which of the following methods is/are used by web browser to control the applet?

  1. Wait()

  2. Destroy()

  3. Dead()

  4. Both 1 and 3

  5. Both 1 and 2


Correct Option: B
Explanation:

This is the correct option because destroy() method is invoked when browser exits normally to inform the applet that is no longer needed and should release any recourses allocated.So this is the correct method. Hence this is correct choice according to the question asked.

Which of the following methods is/are not necessary to define a class, if it implements the Window Listener Interface?

  1. windowMoved()

  2. windowClosing()

  3. windowIconified()

  4. windowActivated()

  5. windowDeiconified()


Correct Option: A
Explanation:

If a class implements an interface then it is necessary for that class to define body to all the methods defined in the interface it is implementing.But windowMoved() method is not present in windowListener interface.So when a class will implement this interface this method need not to be define in the class.So this option is correct.

Which of the following event types is/are invalid in Java?

  1. FocusEvent

  2. ComponentEvent

  3. AdjustmentEvent

  4. Both 2 and 3

  5. None of these


Correct Option: E
Explanation:

As the reason explained all of the given event types are valid in java.So this option is correct.

Which of the following methods cannot be invoked from the instance of Frame class in AWT?

  1. setLocation(int, int)

  2. setVisible(Boolean)

  3. setSize(int, int)

  4. setDefaultCloseOperation(int)

  5. pack()


Correct Option: D
Explanation:

This function is not defined in the Frame class. This function is defined in JFrame class in Swings.So this method cannot be invoked using the object of Frame class.But can be invoked using the Object of JFrame class.This method specifies the operation when the frame is closed.So the following line would be false.Frame f1 = new frame();f1.setDefaultCloseOperation(int);so this is the correct answer.

Which of the following is the subclass of RuntimeException?

  1. IllegalArgumentException

  2. NullPointerException

  3. IOException

  4. IndexOutOfBoundException

  5. ArithmeticException


Correct Option: C
Explanation:

IOException is not a subclass of RuntimeException class, this class is a Subclass of Exception class.This exception is thrown when invalid input/output are given.So this is the correct answer as this is not a subclass of RuntimeException class.

Which of the following is not a method of the scanner class object in Java?

  1. next()

  2. nextLine()

  3. nextInt()

  4. nextChar()

  5. nextLong()


Correct Option: D
Explanation:

There is no function defined in Scanner class to take character input. So there is no function named nextChar().So this is the correct answer.

How many constructors is/are present in BorderLayout in java?

  1. 5

  2. 4

  3. 3

  4. 2

  5. 1


Correct Option: D
Explanation:

This is correct answer because there are two constructors of borderlayout are present in java.these are:-BorderLayout() :- creates a default borderlayout.BorderLayout(int hgap, int vgap) :- create a borderlayout with specified horizontal and vertical gap between the components.So this answer is correct.

Which of following layout managers is/are present in Java awt?

  1. Gridlayout

  2. Flowlayout

  3. Cardlayout

  4. Both 1 and 2

  5. All of these


Correct Option: E
Explanation:

This is correct answer because all of the given layout managers are present in java awt.

Which of the following statements is/are correct?

Color c1 = new Color(284,60,189);

  1. A new color will be created.

  2. There will be a runtime exception.

  3. Parameters are not enough.

  4. There will be an error Compile time error : cannot find method color.

  5. Compile time error : Color is abstract, cannot create an object.


Correct Option: B
Explanation:

This is the correct answer because color constructor creates a new colour but it takes parameters in the range 0-255. But here the value passed is 284(in first parameter).So a runtime exception named “IllegalArgumentException” will be thrown by the JVM.So this is the correct answer.

Which of the following methods is not defined in the Graphics class in Java?

  1. fillRect()

  2. fillCircle()

  3. fillOval()

  4. fillArc()

  5. none of these


Correct Option: B
Explanation:

This option is correct because there is no method defined fillCircle() in Graphics class.So this option is correct.

The number of parameters passed to the constructor of the Font class in Java is

  1. 4

  2. 3

  3. 2

  4. 1

  5. None of these


Correct Option: B
Explanation:

This is correct choice because the constructor of the Font class takes Three parameters :-First :- first parameter is of String type which specifies the name of the Font.Second :- second parameter is of type int which specifies the style of the font like Font.BOLD.Third :- third parameter is of type int which specifies the size of the font.ExampleFont f1 = new Font(“Serif”, Font.BOLD, 32);So this option is true.

Which of the following source objects does not generate the ActionEvent?

  1. JRadioButton

  2. JCheckBox

  3. JComboBox

  4. JList

  5. JTextField


Correct Option: D
Explanation:

This is false choice because JList doesn’t generate an ActionEvent. When we click an item in JList ListSelectionEvent is generated.So this is the true choice according to the question.

How many primitive data types are available in Java?

  1. 9

  2. 6

  3. 8

  4. 7

  5. 5


Correct Option: C
Explanation:

This is correct choice because there are 8 primitive data types in java. These are :-ByteShortIntLongDoubleCharFloatBooleanSo this is correct answer.

How many constructors are there for FlowLayout?

  1. 5

  2. 4

  3. 3

  4. 2

  5. 1


Correct Option: C
Explanation:

This is correct answer because there are only three constructors are there for FlowLayout. These are:-FlowLayout() :- create a default flowLayoutFlowLayout(int Alignment) :- creates a flowlayout with specified alignment, where alignment can take value, FlowLayout.LEFT, FlowLayout.LEFT ,FlowLayout.LEFTFlowLayout(int alignment , int hgap , int vgap) :- same as second constructor with specified horizontal and vertical gap between the components.So this answer is correct.

Which of the following methods is/are valid in Java for handling events?

  1. mouseEnetered()

  2. keyReleased()

  3. mouseDragged()

  4. both 1 and 2

  5. all of these


Correct Option: E
Explanation:

This is correct answer because all of the given methods are valid in java event handling.

- Hide questions