CMSC132 Exam #1
Serializing Objects - answer An object can be represented as a sequence of bytes that
includes the objects data as well as information about the objects type and the types of
data stored.
Super() - answer A method call in a sub class constructor invokes the superclass
constructor
Overloading - answer Having multiple methods with same name but different signatures
in a class
Overriding - answer Overrides the functionality of an existing method but not if it is
marked final
Inheritance - answer The process where one object acquires the properties of another
Is-A Relationship - answer Animal is the superclass of Mammals class therefore
Mammals _______ Animal
Has-A Relationship - answerDetermines whether a certain class _______ certain thing
(hint: some sort of relationship between super class and sub class)
Downcasting - answerSuperclass to subclass
Upcasting - answerSubclass to superclass
- not allowed because it throws an exception
Scanner - answerBreaks input into logical constructs, delimited by whitespace
(hint: Some methods include: hasNext(), nextInt(), next(), etc. of the java I/O)
Syntax for Scanner - answerScanner sc = new Scanner(System.in)
int i = sc.nextInt() //for int
String s = sc.next() //for String
equals(object obj) using getClass() - answerCompares memory reference
if(obj == this)
return true;
else if(obj != null && obj.getClass() == this.getClass())
Platypus p = (Platypus) obj;
return name.equals(p.name) && weight == p.weight etc.
, equals(object obj) using instanceof - answerCompares memory reference
if(obj == this)
return true;
else if(obj instanceof Platypus)
Platypus p = (Platypus) obj;
return name.equals(p.name) && weight == p.weight etc.
else return false;
instanceof vs. getClass() - answerinstanceof does the same thing but getClass() has to
make sure that object being compared is not null
hence: obj != null && obj.getClass() == this.getClass()
Inner Class - answerIs a class defined inside the scope of another class
Static Nested Classes - answerA nested class that's declared as a static class
Attributes of a Static Nested Class - answer- Can ONLY access static fields and
methods of the outer class
- No link to an instance of the outer class
- Is not associated with an outer class
- Does not survive longer than an outer class
(Answer: Attributes of a ____ ____ Class)
Different type of Inner Classes - answer1) Static Nested class
2) Anonymous class
3) Member Inner class // did not learn yet
3) Method-Local Inner class // did not learn yet
(Answer: Different type _____ Class)
What are Inner Class good for? - answer1) Can access all fields & methods of the
enclosing class
2) Increases the level of Encapsulation
3) Private helper class
- logical grouping of functionality
- Data hiding
4) Linkage to outer class
- An inner class object is tied to an outer class object
Enum Types - answerA type that has a fixed set of values, specifies all possible values
by listing them.
(hint: values(),valueOf(), name(), compareTo()...)
Encapsulation - answerTechnique of making the fields/methods/class in a class private
and providing access
Serializing Objects - answer An object can be represented as a sequence of bytes that
includes the objects data as well as information about the objects type and the types of
data stored.
Super() - answer A method call in a sub class constructor invokes the superclass
constructor
Overloading - answer Having multiple methods with same name but different signatures
in a class
Overriding - answer Overrides the functionality of an existing method but not if it is
marked final
Inheritance - answer The process where one object acquires the properties of another
Is-A Relationship - answer Animal is the superclass of Mammals class therefore
Mammals _______ Animal
Has-A Relationship - answerDetermines whether a certain class _______ certain thing
(hint: some sort of relationship between super class and sub class)
Downcasting - answerSuperclass to subclass
Upcasting - answerSubclass to superclass
- not allowed because it throws an exception
Scanner - answerBreaks input into logical constructs, delimited by whitespace
(hint: Some methods include: hasNext(), nextInt(), next(), etc. of the java I/O)
Syntax for Scanner - answerScanner sc = new Scanner(System.in)
int i = sc.nextInt() //for int
String s = sc.next() //for String
equals(object obj) using getClass() - answerCompares memory reference
if(obj == this)
return true;
else if(obj != null && obj.getClass() == this.getClass())
Platypus p = (Platypus) obj;
return name.equals(p.name) && weight == p.weight etc.
, equals(object obj) using instanceof - answerCompares memory reference
if(obj == this)
return true;
else if(obj instanceof Platypus)
Platypus p = (Platypus) obj;
return name.equals(p.name) && weight == p.weight etc.
else return false;
instanceof vs. getClass() - answerinstanceof does the same thing but getClass() has to
make sure that object being compared is not null
hence: obj != null && obj.getClass() == this.getClass()
Inner Class - answerIs a class defined inside the scope of another class
Static Nested Classes - answerA nested class that's declared as a static class
Attributes of a Static Nested Class - answer- Can ONLY access static fields and
methods of the outer class
- No link to an instance of the outer class
- Is not associated with an outer class
- Does not survive longer than an outer class
(Answer: Attributes of a ____ ____ Class)
Different type of Inner Classes - answer1) Static Nested class
2) Anonymous class
3) Member Inner class // did not learn yet
3) Method-Local Inner class // did not learn yet
(Answer: Different type _____ Class)
What are Inner Class good for? - answer1) Can access all fields & methods of the
enclosing class
2) Increases the level of Encapsulation
3) Private helper class
- logical grouping of functionality
- Data hiding
4) Linkage to outer class
- An inner class object is tied to an outer class object
Enum Types - answerA type that has a fixed set of values, specifies all possible values
by listing them.
(hint: values(),valueOf(), name(), compareTo()...)
Encapsulation - answerTechnique of making the fields/methods/class in a class private
and providing access