Please explain these:
1. In general are attributes public and methods are private?
2. Suppose you must define a class called PlayingCard. What are two examples of attributes and two examples of behaviors for this class?
3. Define a single constructor for this class.
public class Student
{
//attributes
private String studentID;
private double gpa;
private boolean hasFunding;
private String major;
//constructor definition
}
4. Rewrite the above code so that it requires as few lines as possible:
String s;
Fraction f;
f = new Fraction( 100, 200 );
s = f.toString( );
System.out.println( s );
5. How many objects are instantiated in the code below:
String s;
Fraction f, g;
Point w, x;
JFrame j;
f = new Fraction(25, 35);
g = f;
w = new Point(5, 10);
6. How many objects are instantiated in the code below:
String title = "Push Me"
JButton one = new JButton(title);
JButton two;
two = one;
7. Is length is an attribute of the String class?
8. Does this line of code compile:
String herName = new String("Naomi");
9. Is an object instantiated in the heap when this line of code is executed?
String hisName = "Dan Jones";
10. In the following code what is displayed on the screen (case sensitive)
String x;
x = new String("Goodbye");
x.toUpperCase( );
System.out.println( x );
11. In the following code how many String objects are instantiated?
String y, z;
y = new String("This is easier than I thought!");
z = y.substring(11, 13);