Albert2, Class, Method - Docx 2887
Albert2, Class, Method - Docx 2887
There are several types of shoes; casual, dress, sports, running, and
snow.
A-The attributes shoe_type and color must be declared String type and price must be declared double.
B-The attribute brandName must be of the type int. Other attributes are fine.
C-The attribute price has to be of type double. Other attributes are fine.
D-The attribute shoe_type has to be of type String. Other attributes are fine.
E-The attribute brandName has to be of type int. Other attributes are fine.
2. Create a class named 'Student' with String variable 'name' and integer variable 'roll_no'. Create a new
object in driver class. Assign the value of roll_no as 2 and that of name as "John" by creating an object
of the class Student.
ss Student{
3. Consider the following class.
public class CrazyArithmetic{
String answer;
public Customer(int cNum, String fName, String lName, String hPhone, double
totPurch)
{
custNum = cNum;
firstName = fName;
lastName = lName;
homePhone = hPhone;
totPurchaseAmt = totPurch;
}
public Customer(int cNum, String fName, String lName, double totPurch)
{
custNum = cNum;
firstName = fName;
lastName = lName;
totPurchaseAmt = totPurch;
}
5.
public class Sport {
public void playGames() {
// code is not included
}
public static void main(String args[] ){
Sport game= null;
game.playGames();
System.out.println(" I played games");
}
}
Which of the following statements are true for the above code?
A-The code will print out: I played games.
B-The code will throw NullPointerException.
C-The code will run without error.
D-The null reference to call the method playGames() causes an error.
E-The variable game can't point to a null value.
6. Consider the following class declaration Student used for an Art Program.
public class Student {
int studentID;
String firstName;
String lastName;
String course1;
String course2;
String course3;
public Student ( int ID, String f_name, String l_name, String cs1, String cs2 ,
String cs3) {
studentID=ID;
firstName =f_name;;
lastName= l_name;
course1=cs1;
course2=cs2;
course3=cs3;
}
public Student ( int ID, String f_name, String l_name, String cs1) {
studentID=ID;
firstName =f_name;;
lastName= l_name;
course1=cs1;
}
public Student ( int ID, String f_name, String l_name, String cs1, String cs2) {
studentID=ID;
firstName =f_name;
lastName= l_name;
course1=cs1;
course2=cs2;
}
//code for other methods and variables not included
}
Which of the following constructors would create the following objects?
Amy, who registered for Painting, Drawing, and Sculpture.
Anish, who registered for Drawing.
(I)
Student Amy =new Student ( "1", "Amy", "Welly", "Drawing", "Painting", "Sculpture");
Student Anish =new Student ( "23", "Anish", "Shah", "Drawing");
(II)
Student Amy =new Student ( 1,"Amy", "Welly", "Drawing", "Painting", "Sculpture");
Student Anish =new Student ( 23,"Anish","Shah", "Drawing");
(III)
Student Amy =new Student ( "1", "Amy", "Drawing", "Painting", "Sculpture");
Student Anish =new Student ( "23", "anish", "shah", "Drawing", "Painting");
(IV)
Student Amy =new Student ( 1,"Welly", "Drawing", "Painting", "Sculpture");
Student Anish =new Student ( 23,"Shah", "Drawing");
A
ChocolateBar small = new ChocolateBar();
ChocolateBar big =new ChocolateBar(8,8);
B
ChocolateBar small = ChocolateBar();
ChocolateBar big = ChocolateBar(8,8);
C
ChocolateBar small = New chocolateBar();
ChocolateBar big =New chocolateBar(4,4);
D
ChocolateBar small = new ChocolateBar(4,4);
ChocolateBar big =new ChocolateBar();
E
ChocolateBar small = new ChocolateBar();
ChocolateBar big =new ChocolateBar(8);
Which of the following answers best describe the code that can replace the missing code?
I.
Employee emp1 = new Employee ("James" , "Green");
Employee emp2 = new Employee ("Sheen" , "Blue");
Employee emp3 = new Employee ("null","null");
II.
Employee emp1 = new Employee ("James" , "Green");
Employee emp2 = new Employee ("Sheen" , "Blue");
Employee emp3 = new Employee (null, null);
III.
Employee emp1 = new Employee ("James" , "Green");
Employee emp2 = new Employee ("Sheen" , "Blue");
Employee emp3 = new Employee ();
IV.
Employee emp1 = new Employee ("James" , "Green");
Employee emp2 = new Employee ("Sheen" , "Blue");
Employee emp3 = New Employee ();
V.
Employee emp1 = new Employee ("James" , "Green");
Employee emp2 = new Employee ("Blue " , " Sheen ");
Employee emp3 = new Employee ();
A
SnackBox nosnack = new SnackBox();
SnackBox fewthings = new SnackBox(5);
SnackBox cookiebox = new SnackBox("cookies", 8);
B
SnackBox nosnack = new SnackBox();
SnackBox fewthings = new SnackBox("cookies", 8);
SnackBox cookiebox = new SnackBox(5);
C
SnackBox nosnack = new SnackBox("cookies", 8);
SnackBox fewthings = new SnackBox(5);
SnackBox cookiebox = new SnackBox();
D
SnacKBox nosnack = new Snackbox();
SnaCkBox fewthings = new Snackbox(5);
SnackBox cookiebox = new Snackbox("cookies", 8);
E
SnackBox nosnack = SnackBox();
SnackBox fewthings = SnackBox(5);
SnackBox cookiebox = SnackBox("cookies", 8);
13. Consider the class below.
public class Example{
public int number;
public Example(int n){
number = n;
}
public int getNumber(){
return number;
}
public void setNumber(int n){
number = n;
}
}
In a client class, which of the following will display the number 7?
A
Example e = new Example(5);
System.out.println(e.getNumber(7));
B
Example e = new Example(5);
System.out.println(e.setNumber(7));
C
Example e = new Example(7);
e.getNumber();
D
Example e = new Example(5);
e.setNumber(7);
System.out.println(e.getNumber());
E
Example e = new Example();
e.setNumber(7);
System.out.println(e.getNumber());