What kind of events can a menuitem object generate - the


1, True or False: A variable has a value that can not be changed by the program.

Select one:

True
False

2, Which of the following is not a loop structure?

Select one:

a. While structure
b. For structure
c. Do .. while structure
d. Block structure

3, Which of these statements is correct?

a. The repaint() method in an applet actually draws something on the applet.

b. The repaint() method does not itself call either the paint() or update() method.

c. The repaint() method only tells the system that it should call paint(). The system will call the paint() method later, when it gets a chance.

d. In general, repaint() is called by a program when the picture drawn on the applet has to change.

Select one:
a. a.
b. b.
c. c.
d. d.

4; True or False: An object is an instance of a class?

Select one:

True
False

5, Examine the following class

public class PatientRecord {
public String lastname; // Patient's last name
public int age; // Patient's age on admission
public bool sex; // Indicates if patient is male or female
}
Initial values of lastname, age and sex instance variables will be:

Select one:

a. String, 0, true
b. null, 0, false
c. String, int, boolean
d. null, 0, true


6, Which statements are true?

1. Declaring a variable does not build an object.
2. In Java, no variable can ever hold an object.
3. You can build an object in Java by declaring it.
4. A variable can only hold a reference to an object.

Select one:

a. All of the above
b. 2, 3, 4
c. 2, 4
d. 1, 3, 4

7, What is output of the program below?
class conditional {
public static void main(String args[]) {
int i = 20;
int j = 55;
int z = 0;
z = i < j ? i : j; // ternary operator
System.out.println("The value assigned is " + z);
}
}

Select one:

a. 55
b. 20
c. 75
d. 0

8, What is the output of the following program:

public static void main(String[] args) {
int N = 1;
while (N <= 32) {
N = 2 * N;
System.out.print(N+", ");
}
}

Select one:

a. 2, 4, 8, 16, 32, 64,
b. 2,4,8,16,32,
c. 1,2,4,8,16,32,
d. 1,32,2,32,2,1

9, What is the result of the following code?

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class Test extends JFrame {
public Test() {
Border border = new TitledBorder("My button");
JButton jbt1 = new JButton("OK");
JButton jbt2 = new JButton("Cancel");
jbt1.setBorder(border);
jbt2.setBorder(border);
getContentPane().add(jbt1, BorderLayout.NORTH);
getContentPane().add(jbt2, BorderLayout.SOUTH);
}
public static void main(String[] args) {
JFrame frame = new Test();
frame.setSize(200, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

Select one:

a. Two buttons displayed with the same border.
b. Two buttons displayed, but only one button has the border.
c. The program has a syntax error because you assign new TitledBorder("My button")to a variable of the Border type.
d. The program has a runtime error because you cannot set a border on a button.

10, Given the following code what will the output be?
int N;
for' (N=1; N<=1;N++)
System.out.print(N)

Select one:
a. 0
b. 1
c. 2
d. No output

11,Which of these statements is correct?

a. The repaint() method in an applet actually draws something on the applet.
b. The repaint() method does not itself call either the paint() or update() method.
c. The repaint() method only tells the system that it should call paint(). The system will call the
paint() method later, when it gets a chance.
d. In general, repaint() is called by a program when the picture drawn on the applet has to
change.

Select one or more:

a. a.
b. b.
c. c.
d. d.

12, The default layout out of a JPanel is __________.

Select one:

a. FlowLayout
b. GridLayout
c. BorderLayout
d. None

13, True or False: Java is not a "platform-independent language".

Select one:

True

False

14, ______ search is the process of searching an array by looking at each item in turn; while ______ search is a method for searching for a given item in a sorted array.

Select one:

a. Linear ... eliminatory
b. Binary ... linear
c. Linear ... binary
d. Binary .... half-list


15, True or False: Subroutines that do NOT return a value are called functions.

Select one:

True

False

16, Java is a platform independent language which of the following best describes what this means:

Select one:

a. Java can be compiled into a machine code that can be executed by the CPU of a computer
b. Java compilers are available for many different operating systems and architectures
c. Java is compiled into bytecode which is machine code designed to be executed by a virtual machine and such virtual machines can be developed for any computer or operating system
d. Java is a high level language that is easy to understand

17, Consider the following code:

import java.awt.*;
import javax.swing.*;
public class Test {
public static void main(String[] args) {
Component c = new JButton("OK");
JFrame frame = new JFrame("My Frame");
frame.add(c);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

Select one:

a. You cannot add a Swing component directly to a JFrame. Instead, you have to add it to a JFrame's contentPane using frame.getContentPane().add(c).

b. You cannot assign a JButton to a variable of java.awt.Component.

c. You can only add c to a container because c's type is Component.
d. None of the above.

18, Variables declared inside of a subroutine are called:

Select one:

a. Local variables
b. Static variables
c. Objects
d. Member variables

19, What does the key word extends in the following code do?

Select the best answer.
class B extends A{
,,,
}

Select one:

a. It creates a class named B that inherits the structures and behaviors of the class named A

b. It allocated memory for a new class B that is larger than class A

c. It defines class B to be a superclass of class A

d. It is not a valid modifier

20, What is the output of the following code?

public class Test {
public static void main(String[] args) {
String s1 = "Welcome to Java!";
String s2 = s1;

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}

Select one:
a. s1 and s2 reference to the same String object

b. s1 and s2 reference to different String objects

21,Which of the following is NOT a control structure?

Select one:

a. If statement
b. A loop
c. A branch statement
d. A variable

22, True or False: In Java 8, Given the code of following interfaces:
Is the following class code correct?

Select one:

True
False

23, Consider these sentences about classes and objects:

1. Classes are used to create objects.
2. The non-static variable declarations and non-static method definitions in the class specify the instance variables and methods that the objects will contains.
3. The objects are said to be "instances" of the class or to "belong" to the class.
4. A class specifies the common properties of a set of objects, namely all the objects that are instances of that class.

Which of the statements above are true?

Select one:

a. 1 and 3.
b. All of them.
c. 1, 3, and 4.
d. 2 and 4.

24, In the following code, what is the printout for list2?

class Test {
public static void main(String[] args) {
int[] list1 = {1, 2, 3};
int[] list2 = {1, 2, 3};
list2 = list1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;
for (int i = 0; i < list2.length; i++)
System.out.print(list2[i] + " ");
}
}

Select one:

a. 1 2 3
b. 1 1 1
c. 0 1 2
d. 0 1 3

25, When is the special variable this used? Please select the best answer.

Select one:

a. To provide a reference an object within the object that a method is calling from
b. To reference an object within a superclass
c. To reference an object within a subclass
d. It references the constructor method within a class

26, Look at this sequence of statements:

Dog dog, dog1, dog 2, dog3;
dog = new Dog();
dog1 = new Dog();
dog3 = dog1;
dog2 = null;
dog.name = "Cheeky";
dog1.name = "Rusty";

Now, what is the output of the following command?

System.out.println(dog3); ?

Select one:

a. null
b. Rusty
c. 0
d. Cheeky

27, Which of the following statements are true?

Select one or more:

a. Each event class has a corresponding listener interface.
b. The listener object's class must implement the corresponding event-listener interface.
c. A source may have multiple listeners.
d. The listener object must be registered by the source object.
e. A listener may listen for multiple sources

28, A byte can be of what size

Select one:

a. -128 to 127
b. (-2 power 8 )-1 to 2 power 8
c. -255 to 256
d. depends on the particular implementation of the Java Virtual machine

29,Given the following code what will the output be?
int[] list = new int[] { 2, 3, 5, 7, 11, 13 };
System.out.println(list[2]);

Select one:

a. 3
b. 5
c. 2
d. 7

30, True or False: Classes that have been grouped together in Java are referred to as packages?

Select one:

True

False


31,True or False: The while loop repeats a set of code while the condition is false.

Select one:

True
False

32, Suppose that the first line of a subroutine definition is: static void test(int n, double x).
Now consider these statements:
test(17,42)
test(0.17,3.227)
Which of those statements is a legal subroutine call?

Select one:

a. Both 1 and 2
b. 1
c. 2
d. Neither 1 nor 2

33,True or False: A variable whose type is given by an abstract class can only refer to objects that belong to concrete subclasses of the abstract class.

Select one:

True
False

34, In the following class which method is the constructor?
Public class MyClass{
public int x;
public int y;

public MyClass(intvall,int val2){
X= Val1;
Y= Val2;
}

public void check1(x,y) {
if (x < y)
System.out.printIn("x is less than y");
}
public void check2(x,y) {
if(x>y)
System.out.printIn{"X is greater than Y")
}
}

Select one:

a. MyClass
b. check1
c. check2
d. None, the default constructor will be generated

35, Executing the ____ statement will cause the program to immediately continue execution the block of statements that were within the loop.

Select one:

a. continue
b. goto
c. break
d. return

36, The ____ statement will repeat a block of statements a specific number of iterations by initializing an integer, incrementing it and testing to determine when the integer reaches a predetermined
test value.

Select one:
a. do .. while
b. while
c. for
d. for each

37, In Java 8, the lambda expression was introduced and it can be used in place of an anonymous that implements an interface that defines just one method.

Which of the follow statements DOES NOT have correct lambda expression syntax:

Select one:

a. (int a, int b) -> a + b;
b. public void run() {System.out.println("testing")};
c. (X, Y) -> X / Y;
d. () -> System.out.println("Hello World");

38, To draw a circle with radius 20 centered at (50, 50) for a graphics object obj, use this method:

Select one:

a. obj.drawOval(30, 30, 40, 40)
b. obj.drawOval(50, 50, 20, 20)
c. obj.drawOval(50, 50, 40, 40)
d. obj.drawOval(30, 30, 20, 20)

39, The area of a circle of radius r is given by 3.14159*r2. Which of the following programs computes and prints the area of a circle of radius 17.42.

a.
public class Area {
public static void main(String[] args) {
double radius;
double area;
radius = 17.42;
area = 3.14159 * radius * radius;
System.out.println( "The area of a circle of radius " + radius + " is " + area );
}
}

b.
public class Area {
public static void main(String[] args) {
double radius;
double area;
radius = 17.42;
area = 3.14159 * (radius + radius);
System.out.println( "The area of a circle of radius " + radius + " is " + area );
}
}

c.
public class Area {
public static void main(String[] args) {
double area;
area = 3.14159 * radius + 17.42 * radius;
System.out.println( "The area of a circle of radius " + radius
+ " is " + area );
}
}

d.
public class Area {
public static void main(String[] args) {
double radius;
double area;
radius = 17.42; area = 3.14159 * radius * radius;
System.out.println( "The area of a circle of radius " + area
+ " is " + radius );

Select one:

a. a.
b. b.
c. c.
d. d.

40, A subroutine that is a member of a java class is called a:

Select one:

a. API
b. Black box
c. Method
d. Sub class


41, The method .... places a menu bar mb into the frame f.

Select one:

a. f.setJMenu(mb)
b. f.add(mb)
c. f.setMenuBar(mb)
d. f.addBar(mb)

42, Study the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends A {
public static void main(String[] args) {
A frame = new Test();
frame.setSize(200, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class A extends JFrame implements ActionListener {
JButton jbtCancel = new JButton("Cancel");
JButton jbtok = new JButton("OK");

public A() {
getContentPane().setLayout(new FlowLayout());
getContentPane().add(jbtCancel);
jbtCancel.addActionListener(this);
getContentPane().add(jbtok);
jbtok.addActionListener(this);

}

public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtCancel) {
System.out.println("Cancel button is clicked");
}
if (e.getSource() == jbtok) {
System.out.println("OK button is clicked");
}
}
}

Select one:

a. The program displays Cancel button on the left of the OK button.
b. When you click the OK button the message "OK button is clicked" is displayed.
c. When you click the Cancel button the message "Cancel button is clicked" is
displayed.
d. All of the above

43, Which of the following is NOT a primitive type within java:

Select one:

a. Int
b. long
c. Boolean
d. String

44, True or False: The base type of an array can include a list of objects not just primitive types?

Select one:
True
False

45, Given the following code. What will the output be?
x=5%2

Select one:

a. The number is less than 3
b. The number is greater than 2
c. The number is less than 8
d. No output

46, What kind of events can a MenuItem object generate?

Select one:

a. ActionEvent
b. ItemEvent
c. ComponentEvent
d. ContainerEvent

47, True or False: The role of the constructor method in a class is to initialize a new object.

Select one:

True
False

48, Which statements are true?
1. Default methods will extend interfaces without having the fear of breaking implementation classes.
2. Default methods are not also referred to as Defender Methods or Virtual extension methods.
3. Default methods has reduced the differences between interfaces and abstract classes.
4. One of the major reason for introducing default methods is to enhance the Collections API in Java 8 to support lambda expressions.

Select one:

a. All of the above
b. 2, 3, 4
c. 2, 4
d. 1, 3, 4

49, Analyze the following code:

class Test {
private double a;

public Test(double a) {
this.t();
this.a = a;
}
public Test() {
System.out.println("Default constructor");
this(1);
}
public void t() {
System.out.println("Invoking t");
}
}

Select one:
a. this.a may be replaced by a.
b. this(1) must be called before System.out.println("Default constructor").
c. this.a() may be replaced by a().
d. this(1) must be replaced by this(1.0).

50, Which of the following statements are correct?
Select one or more:
a. char[][][] charArray = new char[2][2][];

b. char[2][2][] charArray = {'a', 'b'};

c. char[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};

d. char[][][] charArray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}};

Solution Preview :

Prepared by a verified Expert
JAVA Programming: What kind of events can a menuitem object generate - the
Reference No:- TGS02398173

Now Priced at $25 (50% Discount)

Recommended (91%)

Rated (4.3/5)