0

Java Basics

Description: Concept Based Questions
Number of Questions: 15
Created by:
Tags: Concept Based Questions Java Basics
Attempted 0/15 Correct 0 Score 0

Which of the following are not the methods 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.

Which of the following are not the Subclasses 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 event types 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 are not 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: D
Explanation:

As the reason is explained both methods in option 1 and 3 are not used by the web browser to control the applet. So, this option is correct.

Which of following layout managers 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 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 methods is/are not necessary to define for a class if it implement the windowListener 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.

How many constructors are present of 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 the following methods are 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.

How many parameters are passed to the constructor of the Font class in java?

  1. 5

  2. 4

  3. 3

  4. 2

  5. 1


Correct Option: C
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.

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

Which of the following statements about the given statement is/are correct?

  1. A new color will be created.

  2. runtime Exception

  3. Parameters are not enough

  4. 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 source object do 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: ByteShortIntLongDoubleCharFloatBoolean. So, this is correct answer.

Which of the following methods 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.

How many constructors are there for Layout manager 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:- lowLayout():- 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.

- Hide questions