Java Programming Quiz 5: Point Class and String Comparison, Exercises of Computer Science

A java programming quiz focused on completing the point class definition, understanding inheritance and method binding in java, and comparing strings. It includes filling in the blanks for the point class, identifying the correct java keywords for inheritance and incomplete class definitions, and evaluating given expressions related to string comparison.

Typology: Exercises

2012/2013

Uploaded on 04/07/2013

shabi_564
shabi_564 🇮🇳

4.5

(13)

188 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Signature _____________________
CSE 11
Name ________________________
Quiz 5
cs11f ____
Fall 2011
Student ID ____________________
This quiz is to be taken by yourself with closed books, closed notes, no calculators.
Given the following partial class definition for Point,
fill in the blanks to complete the class definition:
The Java keyword which denotes inheritance of interface is ________________________________.
The Java keyword which denotes that a class definition is incomplete is _____________________________.
The Java keyword which denotes inheritance of implementation is _____________________________.
______________________ gives us an "is-a" relationship while _______________________ gives us a "has-a"
relationship.
By default, Java uses dynamic binding of method names. What are the three Java keywords when applied to a
method definition will turn off this dynamic binding and turn on static binding instead?
_____________________ _____________________ _____________________
When using the term dynamic, think ________________ while using the term static, think ________________
public class Point
{
private int x;
private int y;
public Point( int x, int y )
{
setX( x );
setY( y );
}
public int getX()
{
____________________________;
}
public int getY()
{
____________________________;
}
public void setX( int x )
{
___________________________;
}
public void setY( int y )
{
___________________________;
}
}
Given the following expressions, indicate whether
the expressions evaluate to true or false.
String s1 = new String( "CSE 11" );
String s2;
String s3 = s1;
s2 = new String( "CSE 11" );
s1 == s2 __________
s1 == s3 __________
s1.equals( s2 ) __________
s1.equals( s3 ) __________
s1 == "CSE 11" __________
s2 == "CSE 11" __________
pf2

Partial preview of the text

Download Java Programming Quiz 5: Point Class and String Comparison and more Exercises Computer Science in PDF only on Docsity!

Signature _____________________ CSE 11 Name ________________________

Quiz 5

cs11f ____ Fall 2011 Student ID ____________________

This quiz is to be taken by yourself with closed books, closed notes, no calculators.

Given the following partial class definition for Point,

fill in the blanks to complete the class definition:

The Java keyword which denotes inheritance of interface is ________________________________.

The Java keyword which denotes that a class definition is incomplete is _____________________________.

The Java keyword which denotes inheritance of implementation is _____________________________.

______________________ gives us an "is-a" relationship while _______________________ gives us a "has-a"

relationship.

By default, Java uses dynamic binding of method names. What are the three Java keywords when applied to a

method definition will turn off this dynamic binding and turn on static binding instead?

_____________________ _____________________ _____________________

When using the term dynamic, think ________________ while using the term static, think ________________

public class Point { private int x; private int y;

public Point( int x, int y ) { setX( x ); setY( y ); }

public int getX() { ____________________________; }

public int getY() { ____________________________; }

public void setX( int x ) { ___________________________; }

public void setY( int y ) { ___________________________; } }

Given the following expressions, indicate whether

the expressions evaluate to true or false.

String s1 = new String( "CSE 11" ); String s2; String s3 = s1;

s2 = new String( "CSE 11" );

s1 == s2 __________

s1 == s3 __________

s1.equals( s2 ) __________

s1.equals( s3 ) __________

s1 == "CSE 11" __________

s2 == "CSE 11" __________

Given the following class definitions for class Foo, class Fubar1, and class FubarTest:

Given the following (empty) class definition:

public class Quiz {

Fill in the parts the Java compiler will automatically include as it compiles the above into bytecode.

What question would you like to see on the Final Exam?

public class Foo { public Foo( int x, int y ) { this(); System.out.println( "Foo ctor #1" ); }

public Foo() { System.out.println( "Foo ctor #2" ); }

public String toString() { System.out.println( "Foo.toString" ); return "Foo.toString"; } }

public class Fubar1 extends Foo { public Fubar1( int x, int y, int z ) { super( x, y ); System.out.println( "Fubar ctor #1" ); }

public Fubar1( int x, int y ) { this( x, y, -99 ); System.out.println( "Fubar ctor #2" ); }

public String toString() { System.out.println( "Fubar.toString" ); return super.toString() + " + " + "Fubar.toString"; } }

public class FubarTest { public static void main( String[] args ) { Foo ref = new Fubar1( 5, 10 );

System.out.println( "-----" );

System.out.println( ref.toString() ); } }

What is the output when we run FubarTest as in

java FubarTest