Twa kɔ nsɛm atitiriw so
Log in
Sign up for FREE
arrow_back
Laabri

Writing Classes Quiz

star
star
star
star
star
Last updated about 2 years ago
11 Nsɛmmisa
8
8
8
8
8
8
8
8
8
8
20
Asemmisa {{asɛmmisaAhyɛnsode}}
1.

How many instance variables are there in class It?

public class It

{

private int val;

public It()

{

val = 8;

}

public String toString()

{

return "" + val;

}

}

Asemmisa {{asɛmmisaAhyɛnsode}}
2.

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();

}

}

Asemmisa {{asɛmmisaAhyɛnsode}}
3.

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();

}

}

Asemmisa {{asɛmmisaAhyɛnsode}}
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;

}

public String toString()

{

return "" + getIt();

}

}

Asemmisa {{asɛmmisaAhyɛnsode}}
5.

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);

Asemmisa {{asɛmmisaAhyɛnsode}}
6.

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);

Asemmisa {{asɛmmisaAhyɛnsode}}
7.

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);

Asemmisa {{asɛmmisaAhyɛnsode}}
8.

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);

Asemmisa {{asɛmmisaAhyɛnsode}}
9.

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);

Asemmisa {{asɛmmisaAhyɛnsode}}
10.

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;

}

}

Asemmisa {{asɛmmisaAhyɛnsode}}
11.

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.