Purchase Solution

simple java questions

Not what you're looking for?

Ask Custom Question

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

Purchase this Solution

Solution Summary

The solution discusses the answers to some simple java questions.

Solution Preview

See the attached file.

1. In general are attributes public and methods are private?
In general attributes are private and methods are public
2. Suppose you must define a class called PlayingCard. What are two examples of attributes and two examples of behaviors for this class?
Attributes: cardSuite, cardValue
Methods: getSuite, getValue
3. Define a single constructor for this class.
public class Student
{
//attributes
private String ...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Networking Questions

This quiz consists of some basic networking questions.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.