1. int a = 1, b = 2, c = 3;
2. if( b > c || c >= a) {
3. System.out.println(c);
4. } else {
5. System.out.println(b);
6. }
A. 1
1. String name = "Charles";
2. int age = 18;
3. System.out.println("name :" + name);
4. System.out.println("age :" + age);
A. Font?Font f = new Font(Font.serif, Font.BOLD, 10);Font f = new Font("Serif", Font.BOLD + Font.ITALIC, 10);Font f = new Font(Font.serif, Font.bold, 25);Font f = new Font("Serif", Font.bold, 30);string1 and string2 are String.
If the output of the following 2 lines
are the same.System.out.println(string1); System.out.println(string2);
if(string1.equals(string2)) {
System.out.println("a");
} else {
System.out.println("b");
}
A. a
1. float f = 1.234;
2. System.out.println("The number is " + f + " .");
A. compiling error.java MainClass
public class MainClass {
public static int main() {
System.out.println("main 0");
}
public void main(String s) {
System.out.println("main 1");
}
public static void main(String[] args) {
System.out.println("main 2");
}
}
A. main 0 java Test?
public class Test {
public static void main(String[] args) {
double d = 12.3;
Decrementer dec = new Decrementer();
dec.decrement(d);
System.out.println(d);
}
}
public class Decrementer {
public void decrement(double decMe) {
decMe = decMe - 1.0;
}
}
A. 0.0 After execution, which statement is ture?int[] x = new int[25]
java StaticTest
public class StaticTest {
private static int x = 100;
public static void main(String[] args) {
StaticTest t1 = new StaticTest();
t1.x++;
StaticTest t2 = new StaticTest();
t2.x++;
t1 = new StaticTest();
t1.x++;
StaticTest.x++;
System.out.println("x = " + x);
}
}
A. Line 8 cannot be compiled because it is a static reference to a private
variable.
int j = 2;
switch (j) {
case 2:
System.out.println("value is two");
case 3:
System.out.println("value is three");
break;
default:
System.out.println("value is " + j);
break;
}
The output of the program is value is two value is two followed by the text value is three value is two followed by the text value is three,
followed by the text value is 2 value is 2
public class Super {
protected int a ;
protected int b;
public Super(int a, int b) {
this.a = a;
this.b = b;
}
public Super(int a) {
this(a,3);
}
}
public class Sub extends Super{
private int c;
public Sub(int c) {
Super(5);
this.c = c;
}
public static void main(String[] args) {
System.out.println(new Sub(10).b);
}
}
What is the output of java Sub ?
import java.awt.*;
import javax.swing.*;
public class LayoutTest extends JFrame {
JButton button1 = new JButton("Mac");
JButton button2 = new JButton("Window");
JButton button3 = new JButton("Unix");
JButton button4 = new JButton("OS2");
JButton button5 = new JButton("Linux");
public LayoutTest() {
getContentPane().setLayout(new GridLayout(2,3));
getContentPane().add(button1);
getContentPane().add(button2);
getContentPane().add(button3);
getContentPane().add(button4);
getContentPane().add(button5);
getContentPane().add(new JButton("Java"), 4);
getContentPane().remove(2);
}
public static void main(String[] args) {
JFrame f= new LayoutTest();
f.pack();
f.setVisible(true);
}
}
What is the output after we run java LayoutTest?A.
|
B.
|
C.
|
D.
|
import java.awt.*;
import javax.swing.*;
public class LabelTest extends JFrame {
public static void main(String[] args) {
JFrame f= new ButtonTest();
JLabel label = new JLabel("Hi", new ImageIcon("dog.gif"),JLabel.CENTER);
label.setHorizontalTextPosition(JLabel.CENTER);
label.setVerticalTextPosition(JLabel.BOTTOM);
f.getContentPane().add(label);
f.setSize(100,100);
f.setVisible(true);
}
}
What is the output after we run java LabelTest?A.
|
B.
|
C.
|
D.
|
FlowLayout?
FlowLayout() FlowLayout(int alignment)FlowLayout(int hgap, int vgap)FlowLayout(int alignment, int hgap, int vgap)ShowShape extends JFrame. Such that java ShowShape circle
displays a circle with upper left corner at (50,50) and diameter 100 red color. java ShowShape square
displays a square with upper left corner at (50,50) and length 100 yellow color. java ShowShape other strings displays nothing.
// import statements
public class ShowShape extends JFrame {
private String shape;
// your constructor
// paint method
// main method
public static void main(String[] args) {
ShowShape s;
// your code
s.setSize(200,200);
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
s.setVisible(true);
}
}
Programming Question 2(40 pts) NumberButton extends JPanel.
It has the following constructor
It creates row*col buttons. The buttons are added from left to right, top to button. The text on the buttons are numbers, starts withpublic NumberButton(int row, int col, int startNum)
startNum
and the number is increased by 1 on the next button.Thepublic NumButton(int row, int col)
startNum is set to 0.
NumberButton(3,3,19) |
NumberButton(2,4,101) |
NumberButton(3,2) |