Write an interface named xyinterface that contains two int


1. Java is an example of a(n)
a) machine language
b) assembly language
c) high-level language
d) fourth generation language
e) all of the above

2. What does the following code output?

DecimalFormat dfQuestion = new DecimalFormat("#0.###E0");
System.out.println(dfQuestion.format(12.7896987));

a) 12.80E0
b) 12.79E0
c) 12.800E1
d) 1.28E2
e) 0.0128E3

3. If x is an int and y is a float, which of the following is an illegal assignment statement?

a) y = x;
b) x = y;
c) y = (float) x;
d) x = (int) y;
e) all of the above are legal

4. To compare two strings lexicographically, which of the following String methods should be used?

a) equals
b) equalsIgnoreCase
c) compareTo
d) ==
e) all of the above

5. In order to declare a constant, you would use which of the following Java reserved words?

a) private
b) static
c) int
d) final
e) class

6. If two variables contain aliases of the same object then

a) The object may be modified using either alias
b) The object cannot be modified unless there's but a single reference to it
c) A third alias is created if/when the object is modified
d) The object will become an "orphan" if both variables are set to null
e) Answers (a) and (d) are correct

7. Say you write a program that has the following statement in it:
Random rand;

But you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.

a. The program won't run, but it will compile with a warning about the missing class.
b. The program won't compile - you'll receive a syntax error about the missing class.
c. The program will compile, but you'll receive a warning about the missing class.
d. The program will encounter a runtime error when it attempts to access any member of the Random class
e. none of the above

8. Consider the following enumeration:
enum Speed { FAST, MEDIUM, SLOW };
Which of the following statements is correct?

a) The ordinal value of MEDIUM is 2
b) The ordinal value of SLOW is 3
c) The name of the Speed enumeration whose ordinal value is zero is FAST
d) The name of the Speed enumeration whose ordinal value is one is SLOW
e) None of the above

9. Given two String variables, s1 and s2, to determine if they are the same length, which of the following conditions would you use?

a) (s1.equals(s2))
b) (s1.length( ).equals(s2))
c) (s1.length( ).equals(s2.length( ))
d) (s1.length( ) == s2.length( ))
e) length(s1) == length(s2)

10.The String class' compareTo method does which of the following:

a) compares two string in a case-independent manner
b) yields true or false
c) yields 0 if the two strings are identical
d) returns 1 if the first string comes lexically before the second string
e) none of the above

11.What will be displayed by the following command: System.out.println(Math.pow(3, 3-1));

a) 9.0
b) 8.0
c) 6.0
d) 4.0
e) 27.0

12.The relationship between classes and objects is best described as:

a) classes are instances of objects
b) objects are instances of classes
c) objects and classes are the same thing
d) classes are programs while objects are variables
e) objects are the instance data of classes

13.A class' constructor usually defines which of the following

a) how an object is initialized
b) how an object is interfaced
c) the number of instance data in the class
d) the number of methods in the class
e) if the instance data are accessible outside of the object directly

14.Having multiple methods of the same name in a class where each method has a different number of or type of parameters is known as:

a) encapsulation
b) information hiding
c) tokenizing
d) importing
e) method overloading

15.Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

a) foo(0, 0.1);
b) foo(0 / 1, 2 * 3);
c) foo(0);
d) foo( );
e) foo(1 + 2, 3 * 0.1);

16.Every Iterator has which of the following:

a) a hasNext( ) method
b) a hasFirst( ) method
c) a hasNextInt( ) method
d) a isEmpty( ) method
e) none of the above

17.The statement if (x < 0) y = x; else y = 0; can be rewritten using a conditional operator as

a) y = (x < 0) ? x : 0;
b) x = (x < 0) ? y : 0;
c) (x < 0) ? y = x : y = 0;
d) y = (x < 0);
e) y = if (x < 0) x : 0

18.Consider the following paint method:

public void paint(Graphics page)
{
int x, y = 200;
page.setColor(Color.blue);
for (x = 100; x < 200; x += 20)
page.fillRect(x, y, 10, y-x);
}

This paint method will draw several bars (sort of like a bar graph). How many bars will be displayed?

a) 4
b) 5
c) 6
d) 10
e) 20

19.It is easier to correct errors found in a program if

a) they are identified early in the development cycle
b) they are identified during testing
c) they are identified during program use
d) they are identified during maintenance
e) all of the above are equally true, errors are easily corrected in any of these stages

20.It is a bad programming habit to build an initial program and then spend a great deal of time modifying the code until it is acceptable. This is known as which of the following:

a) the prototyping approach
b) the waterfall model
c) iterative development
d) the recursive approach
e) the build-and-fix approach

21.The idea that an object can exist separate from the executing program that creates it is called which of the following:

a) transience
b) static
c) persistence
d) serialization
e) finality

22.In general, spending more time on a better design for a software will do which of the following:

a) shorten testing time
b) slightly reduce maintenance efforts
c) slightly increase maintenance efforts
d) greatly reduce maintenance efforts
e) not alter the time it takes for any other stage whatsoever

23.Which of the following interfaces would be used to implement a class that represents a group of objects?

a) Collection
b) Speaker
c) Comparable
d) MouseListener
e) KeyListener

24.Which of the following Layout Manager types would you use if you want GUI components to be placed at the North, South, East, West and Center of a container?

a) FlowLayout
b) BorderLayout
c) BoxLayout
d) GridLayout
e) TabbedPane

25.Assume this statement: int[] values = {9,4,12,2,6,8,18}; Now the statement: System.out.println(values[7]); will do:

a) output 7
b) output 18
c) output nothing
d) cause an ArrayOutOfBoundsException to be thrown
e) cause a syntax error

Short answer questions:

Answers for the following questions should not exceed three sentences.

26.What is a class variable? How is it defined in Java?

27.Explain how favoring composition over inheritance may improve ObjectOriented Design.
28.What is a wrapper class and when is it usually useful? Give an example of a standard wrapper class?

29.What is the main difference between applets and normal Java programs? Briefly explain.

30.Name all the visibility modifiers in Java. Which one is the preferred visibility for instance variables of a class?

Programming questions:

31.Write a code fragment that declares a two-dimensional 10x10 array of integers called myArray and then initialize each element of the array to have the value of i * j where i and j are the two indices of the element. For instance, the value for element myArray[5][3] must be set to 15 (i.e. 5 * 3).

32.Write an interface named XYInterface that contains two int constants, X = 5 and Y = 10 and a method called useXY which receives no parameters and returns an integer value. (You don't need to implement the XYInterfac)

33.String s1 is said to overlap String s2 if all of the characters in s1 also appear in s2 (in any order). Write a method called testOverlap that takes two strings (called s1 and s2) as input parameters and returns a boolean value that is true if s1 overlaps s2 and false otherwise.

34.Write a class called Employee. Each employee should have a name, an identification number, a position, and an hourly wage.

a) Write a method that is passed the int value of the number of hours worked for the week as a parameter, and returns the pay for the Employee (including overtime, which is 1.5 * hourly wages for each hour over 40).

b) Write a raise method that is passed an increase (or decrease) in hourly wages and updates the Employee's hourly wages appropriately. The amount passed is strictly the amount of increase or decrease, not a new hourly wages. If the amount of increase (or decrease) is more than what the Employee currently makes, do not adjust the hourly wage, but arise an exception called InvalidRaise.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write an interface named xyinterface that contains two int
Reference No:- TGS01294294

Expected delivery within 24 Hours