Question

1) Which of the following is the name of a local variable in the Strange class...

1) Which of the following is the name of a local variable in the Strange class below?

public class Strange{

public static final int MAX = 5;

public static void unknown(){

int number = 0;

for (int i = MAX; i >= 1; i--)

number += i * i;

System.out.println(number);

}

public static void main(String[] a){

unknown();

}

}

a) Strange

b) int
c) MAX
d) number
e) main

2) Which of the following is NOT a method of the Graphics object?

a) getGraphics
b) fillRect
c) drawOval
d) setColor
e) drawString

3) Which of the following statements constructs an object?

a) DrawingPanel panel = new DrawingPanel(200, 100);
b) Scanner console = new Scanner(System.in);
c) Color purple = new Color(200, 0, 200);
d) String name = "Homer Simpson";
e) All of the above statements construct objects.

4) What is the correct syntax for declaring a class constant named BET_LIMIT?

a) public BET_LIMIT = 1000;
b) public final BET_LIMIT = 1000;
c) public static final BET_LIMIT = 1000;
d) public static final int BET_LIMIT = 1000;
e) public static int BET_LIMIT = 1000;

5) Which of the operators listed below has the highest precedence? (Be able to list all operators in order of precedence for the test.)

a) = (assignment)
b) % (modulus)
c) + (addition)
d) () (parentheses)
e) None of the above -- all operators listed here have equal precedence

6) Which of the following are primitive data types in Java (mark all correct answers).

\square int
\square String
\square boolean
\square double
\square private

7) Which of the following is the name of a data type in Java? Mark all that apply. (Recall that every variable is declared using a data type to specify the kind of information that can be stored in the variable.)

a) char
b) String
c) float
d) class
e) for

8) Enter the index value (a number) that identifies the first character in a String object.

9) The abs() method in the Math class is an overloaded method. How many different versions are there?

a) 2
b) 3
c) 4
d) 5
e) 8

10) What is the proper way to instantiate a DrawingPanel object?

a) DrawingPanel dp;
b) DrawingPanel dp = new DrawingPanel();
c) DrawingPanel dp = new DrawingPanel;
d) DrawingPanel dp = new DrawingPanel(500, 500);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) Ans is: d - number

The variable 'number' is local variable which is accessible only in 'unknown()' method

2) Ans is: a - getGraphics

There is no such method called getGraphics is defined inside Graphics class

3) Ans is: e)All of the above statements construct objects.

4) Ans is: d)public static final int BET_LIMIT = 1000;

5) Ans is: d)() (parentheses)
Very first precedence is for () parenthesis and for rest the others are (% Modulus) then (+ Addition) and finaly (= assignment)

6) Ans are: int , boolean , double

7) Ans is: d)class

8) Ans is: 0

9) Ans is: c 4

Explanation: 
double abs(double d)
float abs(float f)
int abs(int i)
long abs(long lng)

10) Ans is: d)DrawingPanel dp = new DrawingPanel(500, 500);


Add a comment
Know the answer?
Add Answer to:
1) Which of the following is the name of a local variable in the Strange class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**...

    in java coorect this code & screenshoot your output ---------------------------------------------------------------------- public class UNOGame {     /**      * @param args the command line arguments      */         public static void main(String[] args) {       Scanner input=new Scanner(System.in);          Scanner input2=new Scanner(System.in);                             UNOCard c=new UNOCard ();                UNOCard D=new UNOCard ();                 Queue Q=new Queue();                           listplayer ll=new listplayer();                           System.out.println("Enter Players Name :\n Click STOP To Start Game..");        String Name = input.nextLine();...

  • LE 7.1 Create a separate class called Family. This class will have NO main(). Insert a...

    LE 7.1 Create a separate class called Family. This class will have NO main(). Insert a default constructor in the Family class. This is a method that is empty and its header looks like this: public NameOfClass() Except, for the main(), take all the other methods in LE 6.2 and put them in the Family class. Transfer the class variables from LE 6.2 to Family. Strip the word static from the class variables and the method headers in the Family...

  • A. What is the value of the following statement? Math.pow(6, 3) B. For the following code:...

    A. What is the value of the following statement? Math.pow(6, 3) B. For the following code: String sentence; String str; sentence = "First exam is on Monday."; str = sentence.replace('s', '$'); C. What type of input does the following program require, and in what order must the input be provided? import java.util.*; public class Strange { static Scanner console = new Scanner(System.in); public static void main(String[] arg) { int x; int y; String name; x = console.nextInt(); name = console.nextLine();...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • What is the final value of the count field? public class Person { private String name;...

    What is the final value of the count field? public class Person { private String name; private int age; private static int count=0; public Person(String name, int age) { this.name = name; this.age age; count++; } public static void main(String[] args) { Person a - new Person("John Doe". 35): Person b new Person("Jane Doe", 38): for(int i=0;i<5;i++) Person tempa

  • 1.The following statement gets an element from position 4 in an array named myArray: x =...

    1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...

  • Please make the following code modular. Therefore contained in a package with several classes and not...

    Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q {    public static LinkedList<String> dogs = new LinkedList<String> ();    public static LinkedList<String> cats = new LinkedList<String> ();    public static LinkedList<String> animals = new LinkedList<String> ();    public static void enqueueCats(){        System.out.println("Enter name");        Scanner sc=new Scanner(System.in);        String name = sc.next();        cats.addLast(name);        animals.addLast(name);    }   ...

  • Identify a logical error in the following code and fix it. public class test1 {    ...

    Identify a logical error in the following code and fix it. public class test1 {     public static void main(String[] args){         int total;         float avg;         int a, b, c;         a=10;         b=5;         c=2;         total=a+b+c;         avg=total/3;         System.out.println("Average: "+avg);     } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT