Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Remember Level chapter1

1. When we invoke repaint() for a java.awt.Component object, the AWT invokes the method:
A. paint()
B. show()
C. draw()
D. update()

Answer: A

2. What does the following line of code do?


TextField text = new TextField(10);
A. Creates the object text and initializes it with the value 10
B. Creates text object that can hold 10 columns of text
C. Creates text object that can hold 10 rows of text
D. The code is illegal

Answer: B

3. The setBackground() method() is a part of the following class in java.awt package:


A. Container
B. Applet
C. Object
D. Graphics

Answer : D

4. Which of the following methods can be used to remove java.awt.Componenr object


from display?
A. hide()
B. disappear()
C. remove()
D. delete()

Answer: C

5. What are controls or components?


a. Controls or components allow users to interact with application
b. Controls or components do not allow users to interact with users
c. Controls or components allow users to interact with users
d. Controls or components allow application to interact with user

Answer : A
6. What are the subclasses of the Container class?
a. Windows, Panel, ScrollPane
b. ScrollPane, Vector, String
c. Thread, Vector, String
d. Applet, InetAddress, Vector
Answer : A

7. Which object is needed to group Checkboxes to make them exclusive?


A. CheckboxGroup
B. Checkbox
C. RadioButton
D. TextField
Answer: A
8. Which class can be used to represent the Checkbox with a textual label that can appear in a
menu?
A. MenuBar
B. MenuItem
C. Checkb oxMenuItem
D. Menu

Answer: C

10. Which are various AWT controls from following?

A. Labels, Push buttons, Check boxes, Choice lists.


B. Text components, Threads, Strings, Servelts, Vectors
C. Labels, Strings, JSP, Netbeans, Sockets
D. Push buttons, Servelts, Notepad, JSP
Answer: A

11.JPanel and Applet use ___________________ as their default layout


A. FlowLayout
B. GridLayout
C. BorderLayout
D. GridBagLayout
Answer: A

12. Which of the following is true about AWT and Swing Component
A. AWT Components Create a process where as Swing Component create a thread
B. AWT Components Create a thread where as Swing Component create a process
C. Both AWT and Swing Component create a process
D. Both AWT and Swing Component create a thread
Answer: A

13. Which of these methods cannot be called on JLabel object?


A. setIcon()
B. getText()
C. setLabel()
D. setBorderLayout()
Answer: D

14. _____________ pane can be used to add component to container


A. GlassPane
B. CotentPane
C. Container
D. All of above
Answer: B

15. Which of the following is not a constructor of JTree


A. JTree(Object obj[])
B. JTree(TreeNode tn)
C. JTree(Vector v)
D. JTree(int x)
Answer: D

16. Swing Components are_______________________


A. Platform dependent
B. Platform Independent
C. Both a & b
D. Platform oriented
Answer: B

Understand Level Questions:

Q17. Which components are needed to get above shown output


A. TextField, Label
B. Choice, Button
C. List, Button
D. Button, TextField
Answer: B
Q18. Which components are needed to get above shown output
A. Menu, MenuItem, MenuBar, Frame
B. List, Label, MenuItem
C. Choice, MenuItem, TextField
D. Label, Frame, Button

Answer: A

Q19. Which components are used in the following output?


A. Label, TextField, Button
B. Applet, Label
C. Applet, Button
D. Grid Layout, Label, Button

Answer: A

Q20. What is the purpose of JTable?

A. JTable object displays rows of data.


B. JTable object displays columns of data.
C. JTable object displays rows and columns of data.
D. JTable object displays data in Tree form.

Answer: C

Q21. Which method is used to display icon on a component?

A. rollOverIcon( ImageIcon i)
B. setIcon(ImageIcon i)
C. displayIcon(ImageIcon i)
D. removeIcon (ImageIcon i )

Answer: B

Q22. What components will be needed to get following output?

A. Label, TabbedPane, CheckBox


B. TabbedPane, List, Applet
C. Panel, TabbedPane, List
D. Applet, TabbedPane, Panel

Answer: c
Apply level questions

23. Debug the following program

import java.awt.*;
import javax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "emp_Name", "emp_id", "emp_salary" };
final Object[][] data = {
{ "Ramesh", "111", "50000" },
{ "Sagar", "222", "52000" },
{ "Virag", "333", "40000" },
{ "Amit", "444", "62000" },
{ "Anil", "555", "60000" },
};
JTable table = new JTable(data);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}

a. Error in statement in which JTable is created


b. Error in statement in which JScrollPane is created
c. Error in statement in which applet tag is declared
d. None of the above

Answer: a

24 Debug the given program so as to get the following output

import java.awt.*;
import javax.swing.*;
/*<applet code="test" width=200 height=200>
</applet>*/
public class test extends JApplet
{
public void init()
{
Container c=getContentPane();
JTabbedPane jp=new JTabbedPane();
JButton b1=new JButton("COMP.TECH");
p1.add(b1);
JButton b2=new JButton("INFO.TECH");
p1.add(b2);
JButton b3=new JButton("ELEC.ENGG");
p1.add(b3);
JButton b4=new JButton("FIRST");
p2.add(b4);
JButton b5=new JButton("SECOND");
p2.add(b5);
JButton b6=new JButton("THIRD");
p2.add(b6);

jp.addTab("Branch",p1);
jp.addTab("Year",p2);
c.add(jp);
}
}

A. JPanel p2=new JPanel();


JButton b3=new JButton("ELEC.ENGG");
B. JPanel p2=new JPanel();
JPanel p1=new JPanel();
C. /*<applet code="test" width=200 height=200>
</applet>*/
D. jp.addTab("Branch");
jp.addTab("Year");
Answer: B
25 Observe the following code
import java.awt.*;
import java.applet.*;
public class LayoutDemo5 extends Applet
{
public void init()
{
int i,j,k,n=4;

setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();

p1.setLayout(new FlowLayout());
p1.add(new TextField(20));
p1.add(new TextField(20));

/*p2.setLayout(new GridLayout(5,3));
p2.add(new Button("OK"));
p2.add(new Button("Submit"));*/

add(p1,BorderLayout.EAST);
add(p2,BorderLayout.WEST);
}
}
/*<applet code=LayoutDemo5.class width=300 height=400>
</applet>*/

What will be the output of the above program?

A. The output is obtained in Frame with two layouts: Frame layout and Flow Layout.
B. The output is obtained in Applet with two layouts: Frame layout and Flow Layout.
C. The output is obtained in Applet with two layouts: Frame layout and Border Layout.
D. The output is obtained in Applet with two layouts: Border layout and Flow Layout.

Answer: D

26 Observe the following code

import java.awt.*;
import javax.swing.*;
public class test extends JFrame
{
public test()
{
super("Login Form");
Container cpane=getContentPane();
cpane.setLayout(new FlowLayout());
JLabel l1=new JLabel("Name");
JLabel l2=new JLabel("Password");
JTextField t1=new JTextField(20);
JTextField t2=new JTextField(20);
JButton b1=new JButton("Login");
JButton b2=new JButton("Cancel");
cpane.add(l1);
cpane.add(t1);
cpane.add(l2);
cpane.add(t2);
cpane.add(b1);
cpane.add(b2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
test obj=new test();
obj.setVisible(true);
obj.setSize(200,200);
}
}

Choose the correct output.

A.

B.
C.

D. None of the above

Answer: C

27 Consider the program given below

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
/*
<applet code="test" width=300 height=100>
</applet>
*/
public class test extends JApplet
{
public void init()
{
Container co = getContentPane();
co.setLayout(new FlowLayout());
JComboBox jc=new JComboBox();
jc.addItem("cricket");
jc.addItem("football");
jc.addItem("hockey");
jc.addItem("tennis");
co.add(jc);
}
}

Choose the correct statement to get the following output

A. JComboBox jc=new JComboBox(“Applet Viewer:test”);


B. JComboBox jc=new JComboBox();
C. JComboBox jc=new JComboBox(“cricket”, “football”, “hockey”, “tennis”);
D. None of the above.

Answer: B

28 Read the following code

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class test extends Applet
{
Font f;
Color c;
public void init()
{
f=new Font("Times New Roman",Font.ITALIC,48);
setFont(f);
c=new Color(255,000,000);
setForeground(c);
}
public void paint(Graphics g)
{
g.drawString("Hello",100,250);
}
}
/*<applet code =test width =90 height=50></applet>*/

What will be the color of the string?


A. Red
B. Blue
C. Green
D. Pink

Answer: A
--------------------------------------------------------------------------------------------------------------------------------

You might also like