Classes Basics Quiz
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
10 Questions
1 point
1
Question 1
1.
How many instance variables are there in class It?public class It{private int val;}
How many instance variables are there in class It?
public class It
{
private int val;
}
1 point
1
Question 2
2.
How many methods are there in class It?public class It{ private int val; public It() { val = 7; } public int getIt() { 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;
}
}
1 point
1
Question 3
3.
How many constructors are there in class It?public class It{ private int val; public It() { val = 7; } public int getIt() { return val; }}
How many constructors are there in class It?
public class It
{
private int val;
public It()
{
val = 7;
}
public int getIt()
{
return val;
}
}
1 point
1
Question 4
4.
How many accessor methods are there in class It?public class It{ private int val; public It() { val = 7; } public int getIt() { return val; }}
How many accessor methods are there in class It?
public class It
{
private int val;
public It()
{
val = 7;
}
public int getIt()
{
return val;
}
}
1 point
1
Question 5
5.
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 int getTotal() { return total; }}//code in the main of another classCheck test = new Check();test.setNums(3,-6);test.add();out.println(test.getTotal());
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 int getTotal()
{
return total;
}
}
//code in the main of another class
Check test = new Check();
test.setNums(3,-6);
test.add();
out.println(test.getTotal());
1 point
1
Question 6
6.
How many modifier / mutator 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() { total = one + two; } public int getTotal() { return total; }}
How many modifier / mutator 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()
{
total = one + two;
}
public int getTotal()
{
return total;
}
}
1 point
1
Question 7
7.
How many instance variables 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() { total = one + two; } public int getTotal() { return total; }}
How many instance variables 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()
{
total = one + two;
}
public int getTotal()
{
return total;
}
}
1 point
1
Question 8
8.
How many constructors 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() { total = one + two; } public int getTotal() { return total; }}
How many constructors 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()
{
total = one + two;
}
public int getTotal()
{
return total;
}
}
1 point
1
Question 9
9.
Consider the class and client code below.public class Aplus{ public double go( double a ) { return a * 3; } public double fun( double b ) { return b * 2; }}//client code in another classAplus x = new Aplus();System.out.println( x.go(2) );
Consider the class and client code below.
public class Aplus
{
public double go( double a )
{
return a * 3;
}
public double fun( double b )
{
return b * 2;
}
}
//client code in another class
Aplus x = new Aplus();
System.out.println( x.go(2) );
1 point
1
Question 10
10.
Consider the class and client code below.public class Aplus{ public double go( double a ) { return a * 3; } public double fun( double b ) { return b * 2; }}//client code in another classAplus x = new Aplus();System.out.println( x.fun(6) );
Consider the class and client code below.
public class Aplus
{
public double go( double a )
{
return a * 3;
}
public double fun( double b )
{
return b * 2;
}
}
//client code in another class
Aplus x = new Aplus();
System.out.println( x.fun(6) );