Java Fundamentals and Concepts, Exams of Advanced Education

A wide range of java fundamentals and concepts, including the lifecycle of parameters, types, objects, and classes, as well as important programming constructs like encapsulation, collections, method overloading, access modifiers, inheritance, interfaces, exceptions, generics, and inner classes. Clear explanations and examples for each topic, making it a valuable resource for students and developers looking to deepen their understanding of the java programming language. The comprehensive coverage of these core java concepts can help readers answer key questions, apply the knowledge in practical programming tasks, and prepare for exams or interviews related to java development.

Typology: Exams

2023/2024

Available from 08/27/2024

Qualityexam
Qualityexam 🇰🇪

2.5

(4)

6.4K documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 132 Exam 1 Study Guide With
100% Complete Solution
What is the only time that data from your program exists? - Correct Answer-When the
program is actually running
All parameters in Java are passed by _________ - Correct Answer-Value
When does a parameter come into existence? - Correct Answer-When the method is
called
When do types come into existence? - Correct Answer-At compilation
Give three examples of predefined types - Correct Answer-Int, char, string
Give an example of a user defined type - Correct Answer-Class
All primitive types are ________ but not all ________ types are primitive - Correct
Answer-Predefined
What is auto-boxing? - Correct Answer-Converting from a primitive type to a wrapper
class object
What is autounboxing? - Correct Answer-Converting from a wrapper class object to a
primitive type
Why do the wrapper classes exist? - Correct Answer-You might need to use a primitive
type somewhere only objects are allowed, like in collections
What is encapsulation? - Correct Answer-Combining data and code into a single object
What is a collection - Correct Answer-Aggregation of multiple elements or a relationship
between them
What is a class - Correct Answer-A user-defined data type
What is an instance of a class - Correct Answer-Object
When do objects come into existence - Correct Answer-At runtime
When do classes come into existence - Correct Answer-Compile time (when program is
written)
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Java Fundamentals and Concepts and more Exams Advanced Education in PDF only on Docsity!

CMSC 132 Exam 1 Study Guide With

100% Complete Solution

What is the only time that data from your program exists? - Correct Answer-When the program is actually running All parameters in Java are passed by _________ - Correct Answer-Value When does a parameter come into existence? - Correct Answer-When the method is called When do types come into existence? - Correct Answer-At compilation Give three examples of predefined types - Correct Answer-Int, char, string Give an example of a user defined type - Correct Answer-Class All primitive types are ________ but not all ________ types are primitive - Correct Answer-Predefined What is auto-boxing? - Correct Answer-Converting from a primitive type to a wrapper class object What is autounboxing? - Correct Answer-Converting from a wrapper class object to a primitive type Why do the wrapper classes exist? - Correct Answer-You might need to use a primitive type somewhere only objects are allowed, like in collections What is encapsulation? - Correct Answer-Combining data and code into a single object What is a collection - Correct Answer-Aggregation of multiple elements or a relationship between them What is a class - Correct Answer-A user-defined data type What is an instance of a class - Correct Answer-Object When do objects come into existence - Correct Answer-At runtime When do classes come into existence - Correct Answer-Compile time (when program is written)

Local variables and parameters are created in what section of memory? - Correct Answer-Runtime stack What area of memory contains objects and arrays - Correct Answer-Heap What's the only way to access an object? - Correct Answer-Indirectly, through references What is aliasing - Correct Answer-Aliasing is having more than one reference variable that refer to the same object What happens to a reference parameter when a method has one and uses it - Correct Answer-The reference argument is copied to the reference parameter, but the object that the reference refers to isn't copied, so aliasing occurs What does 'this' automatically refer to? - Correct Answer-The method's current object name1.method() is called method() is running What's the current object? - Correct Answer-name What are automatically invoked when an object is instantiated - Correct Answer- constructors Does an object already exist when a constructor is called - Correct Answer-yes What happens if you don't write a constructor - Correct Answer-The compiler makes one with default parameters What is a copy constructor? - Correct Answer-This is a special constructor for creating a new object as a copy of an existing object. There will always be only one copy constructor that can be either defined by the user or the system. public Person(Person p) { this.x = p.x; this.y = p.y; this.address = new Address(p.address); } What kind of copying does this constructor do? - Correct Answer-Deep copying public Person(Person p) { this.x = p.x; this.y = p.y; this.address = p.address; }

How would you declare an enumerated type of 4 colors called Colors? Then set the color to red - Correct Answer-public enum Colors {RED, GREEN, BLUE, PINK}; Colors marker = Colors.RED; What are the 3 methods that enum uses? - Correct Answer-values(), valueOf(), and compareTo() How do you declare an enum outside of a class? - Correct Answer- classname.EnumTypeName.ENUMVALUE How many superclasses can a class extend - Correct Answer- What should be the first line in the subclass constructor if you want it to invoke the superclass constructor - Correct Answer-super() Can a subclass reference refer to a superclass object - Correct Answer-no T or F? Anywhere you can use a superclass, you can use a subclass - Correct Answer- T When is instanceOf determined? - Correct Answer-Runtime Through what reference should you call super class methods? - Correct Answer- Superclass Can a superclass reference refer to a subclass object? - Correct Answer-Yes What is downcasting? - Correct Answer-Downcasting is the casting from a general to a more specific type, i.e. superclass casted to subclass type What is upcasting? - Correct Answer-A subclass reference is casted to a superclass type What is method overriding - Correct Answer-Subclass has a method with same name & signature, which overrides original superclass method The type of the version of the method that runs is of the object that the method is called on. When is that decision made? - Correct Answer-runtime What's called? Superclass reference to superclass object.. - Correct Answer-superclass What's called? Subclass reference to subclass object.. - Correct Answer-subclass What's called? Superclass reference to subclass object - Correct Answer-subclass

What's called? Subclass reference to superclass object - Correct Answer-ERROR Can a subclass access the private fields of a superclass - Correct Answer-no Can you override private or static methods - Correct Answer-no Where can a class with a protected modifier be seen? - Correct Answer-In a class and in any direct/indirect subclasses What is shadowing - Correct Answer-Subclass has a field with the same name as the superclass overriding vs overloading: when is the method that's called determined? - Correct Answer-overriding: runtime overloading: compile time If a class is final, it can't have ________ - Correct Answer-subclasses A final method can be nonprivate. T or F? - Correct Answer-T Why do the methods in the Object class exist? - Correct Answer-They're there to be overridden What is an interface? - Correct Answer-Collection of constants and method signatures What's the word you use to utilize an interface with your class? - Correct Answer- implements Can you instantiate an interface? - Correct Answer-No How many interfaces can a class implement? - Correct Answer-as many as it wants What does a class have to do when it implements an interface - Correct Answer-Write all the methods in the interface A reference of interface can only call what? - Correct Answer-the methods in that interface What is composition - Correct Answer-When an object has a field that's a reference to an object Give an example of dereferencing - Correct Answer-reference.fieldName or reference.methodName What is the cause of a compile-time/syntax error - Correct Answer-Error in code construction

Abstract classes: Implementation details are left to _________ - Correct Answer- subclasses A field can be abstract. T or F? - Correct Answer-F Abstract classes: When is it decided which method is called? - Correct Answer-Runtime When can you use abstract methods/classes - Correct Answer-When you don't specifically need to initialize anything in the super class Abstract method has signature but no body. T or F? - Correct Answer-T Does a whole class need to be abstract if a method in it is abstract? - Correct Answer- Yes If you have: public abstract class Shape{} How would you instantiate an object without causing an error? - Correct Answer-Shape s = new Circle(); Why are abstract classes/methods useful - Correct Answer-Keep from code duplication What needs to happen to a subclass if it doesn't override an abstract method in its superclass? - Correct Answer-It has to become abstract itself Can an abstract method be final? - Correct Answer-No Why can't we use an interface instead of an abstract class? - Correct Answer-An abstract class can have fields and methods that an interface can't; nonstatic and nonfinal fields and methods that subclasses can inherit Which clause does a try-catch exception execute if it has multiple? - Correct Answer- The one that matches the exception that was thrown What happens if an exception is not caught by a catch block? - Correct Answer-JVM terminates the program Finally is placed where? (in regards to try-catch blocks) And when will it execute? - Correct Answer-It's at the end and will execute if the try block executes What is generic programming? - Correct Answer-Writing code that can be valid with different types of data If I have: class MyGeneric{}

Give an example of what types can be put in the E (think generics)? - Correct Answer- Integers, Strings, user-defined types Can you instantiate generic type parameters? - Correct Answer-No Give an example of a class definition with a bounded type parameter and describe the bounds - Correct Answer-class MyGeneric2{} Can only use a vehicle or subclass a vehicle for T <T extends Vehicle & Comparable(T)> Valid parameter? - Correct Answer-Yes Say S is a subclass of T Generics (is/is not) a subclass of Generics - Correct Answer-is not Wildcards:? stands for: - Correct Answer-Any type Give two examples of an ArrayList with wildcard parameters: one extending vehicle and including the vehicle superclass - Correct Answer-ArrayList<? extends Vehicle> ArrayList<? super Vehicle> Is it possible to instantiate objects of wildcards? - Correct Answer-No Instantiate a Generic class w type Integer - Correct Answer-Generic m = new Generic(); If you want to make an array that doesn't have a specified type, how can you go about it? Make one called dates with size size - Correct Answer-T[] dates = (T[])new Object[size]; Give an example of how generics are helpful when it comes to seeing problems w the code bc it shows the problems at compile time instead of runtime - Correct Answer-Say you have an arraylist with name of students and an integer is accidentally added instead of a string, when you try to do anything with the data and end up in the index that's an integer, you'll know that it's not going to work because you'll get an error about the type. What's an inner class? - Correct Answer-a class that's defined inside another class How many inner classes can you have in a single outer class - Correct Answer-As many as you want How do you instantiate an inner class so it links to the other class - Correct Answer- Instantiate it with an object of the other class Why are inner classes useful - Correct Answer-Act as private helper classes Visible to one class but not another