Writing Classes Quiz

By Mickey Arnold
Last updated 10 months ago
11 Questions

How many instance variables are there in class It?
public class It
{
private int val;
public It()
{
val = 8;
}
public String toString()
{
return "" + val;
}
}

How many methods are there in class It?
public class It
{
private int val;
public It()
{
val = 7;
}
public int getIt()
{
return val;
}
public String toString()
{
return "" + getIt();
}
}

How many constructors are there in class It?
public class It
{
private int val;
public It()
{
val = 7;
}
public int getIt()
{
return val;
}
public String toString()
{
return "" + getIt();
}
}

How many accessor methods are there in class It?
public class It
{
private int val;
public It()
{
val = 7;
}
public int getIt()
{
return val;
}
public String toString()
{
return "" + getIt();
}
}

What is output by the code below?
public class Check
{
private int fun;
public void change()
{
int fun = 5;
}
public String toString()
{
return "" + fun;
}
}
//client code
Check test = new Check();
test.change();
out.println(test);

What is output by the code below?
public class Check
{
private int fun;
public void change()
{
fun = 5;
int fun = 6;
}
public String toString()
{
return "" + fun;
}
}
//client code
Check test = new Check();
test.change();
out.println(test);

What is output by the code below?
public class Check
{
private int one, two, total;
public void setNums(int n1, int n2)
{
one = n1;
two = n2;
}
public void add()
{
total = one + two;
}
public String toString()
{
return "" + total;
}
}
//code in the main of another class
Check test = new Check();
test.setNums(3,-6);
test.add();
out.println(test);

What is output by the code below?
public class Check
{
private int one, two, total;
public void setNums(int n1, int n2)
{
one = n1;
two = n2;
}
public void add()
{
total = one + two;
two = 5;
}
public String toString()
{
total = 2;
return "" + total;
}
}
//code in the main of another class
Check test = new Check();
test.setNums(-6,3);
test.add();
out.println(test);

What is output by the code below?
public class Check
{
private int one, two, total;
public void setNums(int n1, int n2)
{
one = n1;
two = n2;
}
public void add()
{
one = 5;
total = one + two;
two = 5;
}
public String toString()
{
return "" + total;
}
}
//code in the main of another class
Check test = new Check();
test.setNums(3,2);
test.add();
out.println(test);

How many modifier methods are there in class Check?
public class Check
{
private int one, two, total;
public void setNums(int n1, int n2)
{
one = n1;
two = n2;
}
public void add()
{
one = 5;
total = one + two;
two = 5;
}
public String toString()
{
return "" + total;
}
}

Directions :: Write a Buggy class. Buggy will have width, height, and speed properties. width, height, and speed are integer numbers. You must provide 3 constructors, an equals, and a toString for class Buggy.

One constructor must be a default.
One constructor must be an width and height only constructor.
One constructor must be an width, height, and speed constructor.
You must provide an equals method.
Equals will compare the width, height, and speed properties of two Buggy objects.
You must provide a toString() method.
The toString() should return the width, height, and speed of the Buggy.