SAMPLE
SAMPLE
1.A public top-level Java class may be defined in a source file with any base name as long as the
file extension is .java. __________
2. Java identifiers can contain letters, digits, and the underscore symbol and may start with a
digit.________
3. In Java, char is a primitive data type, while String is an object data type. ___________
4. Java is a strongly typed language; therefore you must declare a data type for all variables.
_____________
5. You’re designing banking software and need to store 10000 customer accounts with
information on the accountholder’s name, balance, and interest rate. The best approach is store
30000 separate variables in the main method. __________________
String s1 = "Hello";
String s2 = "Welcome!";
s1 = s2;
System.out.println("s1: " +s1);
System.out.println("s2: " +s2);
a) s1: Hello
s2: Hello
b) s1: Welcome!
s2: Hello
c) s1: Welcome!
s2: Welcome!
d) s1: Hello
s2: Welcome!
a) 10
b) 0
c) 1
d) ArrayIndexOutOfBoundsException
a) Value of x is 0 Value of y is 1
b) Value of x is 100 Value of y is 1
c) Value of x is 100 Value of y is 1
d) Value of x is 100 Value of y is 101
8.Which of the following declares a one dimensional array named "score" of type int that can
hold 9 values?
a) int score;
b) int[] score;
c) int[] score=new int[9];
d) int score=new int[9];
a) 55555
b) 87668
c) AtlanticPacificIndianArcticSouthern
d) An ArrayIndexOutofBoundsException is thrown.
10. How would you use the ternary operator to rewrite this if statement?
if (gender == "male")
System.out.print("Mr.");
else
System.out.print("Ms.");
a) System.out.print( (gender == "male") ? "Mr." : "Ms." );
b) System.out.print( (gender == "male") ? "Ms." : "Mr." );
c) (gender == "male") ? "Mr." : "Ms." ;
d) (gender == "male") ? "Ms." : "Mr." ;
Question 3: (4 points)
Question 5: (4 points)
The class Employee referres to an entity that consists of attributes such as : emp_id, emp_name
and emp_salary. This class has:
• the default constructor and another appropriate constructor that accepts all three
properties of an employee
• getters and setters methods for these properties
• calculateSalary() method that will change the salary in the condition of: if the salary of
employee is in the range 1000 $ ≤ salary ≤ 5000$ than the salary will increment with 2
%
• the method toString which will return a String composed of values of id, name and
salary of employee.
Complete the empty places denoted by …….. in the Employee class.
public class Employee {
private String emp_id;
private String emp_name;
private int emp_salary;
public Employee() {
this.emp_id= 0;
this.emp_name= “”;
this.emp_salary=0;
}
………………………………………………………………
}