What are two examples of attributes for class


Discuss the below:

Q1. In general are attributes public and methods are private?

Q2. Suppose you must define a class called PlayingCard. What are two examples of attributes and two examples of behaviors for this class?

Q3. 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

}

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

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

Q6. How many objects are instantiated in the code below:

String title = "Push Me"

JButton one = new JButton(title);
JButton two;
two = one;

Q7. Is length is an attribute of the String class?

Q8. Does this line of code compile:

String herName = new String("Naomi");

Q9. Is an object instantiated in the heap when this line of code is executed?

String hisName = "Dan Jones";

Q10. In the following code what is displayed on the screen (case sensitive)

String x;
x = new String("Goodbye");
x.toUpperCase( );
System.out.println( x );

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

Solution Preview :

Prepared by a verified Expert
JAVA Programming: What are two examples of attributes for class
Reference No:- TGS01934146

Now Priced at $25 (50% Discount)

Recommended (94%)

Rated (4.6/5)