Which statement is true with respect to the following code i
Which statement is true with respect to the following code?
import java.awt.*;
import javax.swing.*;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame(\"My Frame\");
frame.getContentPane().add(new JButton(\"OK\"));
frame.getContentPane().add(new JButton(\"Cancel\"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
Select one:
a. Only button OK is displayed.
b. Only button Cancel is displayed.
c. Both button OK and button Cancel are displayed and button OK is displayed on the left side of button Cancel.
d. Both button OK and button Cancel are displayed and button OK is displayed on the right side of button Cancel.
Solution
Ans: b. Only button Cancel is displayed.
frame.getContentPane().add(new JButton(\"OK\"));
This line add OK biutton in entire frame
frame.getContentPane().add(new JButton(\"Cancel\"));
This line override already OK button and add Cancel button on entire frame
![Which statement is true with respect to the following code? import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) Which statement is true with respect to the following code? import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args)](/WebImages/31/which-statement-is-true-with-respect-to-the-following-code-i-1090610-1761574210-0.webp)