Java Section 4 - 6

¡Supera tus tareas y exámenes ahora con Quizwiz!

How many packages can be contained in a Java program? a) As many as you need. b) only one c) none d) three

a) As many as you need.

When you create a static method how will you call that method? a) By typing out the class name first and then the method name. ex. Vehicle.horn( ) b) By just typing out the class name. ex. Vehicle c) By just typing out the method name. ex. horn( ) d) None of the above.

a) By typing out the class name first and then the method name. ex. Vehicle.horn( )

In Java, how is abstraction achieved? a) By using abstract classes and interfaces. b) only with inheritance c) through exceptions d) None of the above.

a) By using abstract classes and interfaces.

In Java, how do you make a class an abstract class? a) By using the Abstract keyword. b) By making a class final. c) By declaring a class public. d) None of the above.

a) By using the Abstract keyword.

When creating getters what is the naming convention? a) Getters start with get, followed by the variable name, with the first letter of the variable name capitalized. b) Getters have no naming convention. c) The getters will start with the variable name first and then you will use get to finish off the naming. d) All of the above.

a) Getters start with get, followed by the variable name, with the first letter of the variable name capitalized.

In order to create your own objects in Java what do you have to have? a) In Java you must have a user defined class that you can instantiate to create an object. b) Multiple inheritance. c) Variables that will have now data. d) All of the above.

a) In Java you must have a user defined class that you can instantiate to create an object.

What does Polymorphism refer to? a) Polymorphism refers to having many forms. b) Polymorphism refers to only having one form. c) Polymorphism refers to static methods. d) All of the above.

a) Polymorphism refers to having many forms.

What is the naming convention for setters in Java? a) Setters start with set, followed by the variable name, with the first letter of the variable name capitalized. b) Setters start with the variable name first and then followed by the set word. c) In java setters do not exists. d) All of the above.

a) Setters start with set, followed by the variable name, with the first letter of the variable name capitalized.

What does the HashSet use for the storage? a) The HashSet uses the hash map for storage. b) The HashSet uses the left table for storage. c) The HashSet uses the right table for storage. d) None of the above.

a) The HashSet uses the hash map for storage.

The LinkedHashSet can contain what? a) The LinkedHashSet can contain unique elements. b) The LinkedHashSet cannot contain unique elements. c) None of the above.

a) The LinkedHashSet can contain unique elements.

What are the attributes in a class? a) The attributes are the variables of fields within a class. b) The attributes are methods in a class. c) Attributes are key words. d) None of the above.

a) The attributes are the variables of fields within a class.

In Java any class that contains an abstract method should be defined as what? a) The class should be defined as an Abstract class. b) A static class. c) It should be defined as a public class. d) All of the above.

a) The class should be defined as an Abstract class.

To override a method the method must have? a) The overriden method must have the same method signature and parameters. b) The overridden method must have the same signature but different parameters. c) The overridden method must have a different signature with the same parameters. d) None of the above.

a) The overriden method must have the same method signature and parameters.

When creating an Enum, how are the values seperated? a) The values of an Enum are separated by a comma. b) The values of an Enum are separated by a dot. c) The values of an Enum are separated by a semicolon. d) None of the above.

a) The values of an Enum are separated by a comma.

What is the class called that is inheriting the properties of another class? a) This class is called the subclass, derived class or child class. b) This class is called the parent class. c) This class is called the polymorphic class. d) None of the above.

a) This class is called the subclass, derived class or child class.

What happens when you declare a variable or method static in Java? a) This means that the variable or method will belong to the class, rather than to a specific instance. b) This means that the variable of method will only belong to the main method. c) This means that the variable or method will only be called when the class in instantiated. d) None of the above.

a) This means that the variable or method will belong to the class, rather than to a specific instance.

How many attributes can you define in a class? a) You can define as many as you want in a class. b) You can only have one attribute in a class. c) The attributes in a class can only be within methods and you can have as many as you need. d) None of the above.

a) You can define as many as you want in a class.

How will you implement encapsulation in Java? a) You can implement encapsulation in Java but using the private access modifier. This will bind the data to the class it resides in while hiding it from the users. b) You can implement encapsulation by using the extends key word in Java. c) All of the above.

a) You can implement encapsulation in Java but using the private access modifier. This will bind the data to the class it resides in while hiding it from the users.

What key word do you use when you want to return a word? a) You can use the String key word for the return type in your method signature. b) You can just return the word. c) You can store the word in an int and then return the int.

a) You can use the String key word for the return type in your method signature.

What do methods define in Object-Oriented Programming? a) behavior b) fields c) state d) classes

a) behavior

A constructor must have the same what as the class it resides in? a) name b) body c) field d) None of the above.

a) name

Can you override a constructor? a) no b) yes c) Yes, but only when the constructor has a return type. d) All of the above.

a) no

Will the set interface allow duplicate values? a) no b) yes

a) no

List the access modifiers in Java? a) public, private, protected, default b) static, private, default, public c) protected, static, default, private, protected d) All of the above.

a) public, private, protected, default

What is the class called whose properties are inherited? a) super class, base class, or parent class b) derived class, child class, or parent class c) base class, child class, or super class d) All of the above.

a) super class, base class, or parent class

Can you overload a constructor? a) yes b) no c) Yes, but only when the constructor is a static constructor. d) None of the above.

a) yes

Can you use static and final together? a) yes b) no c) This will create an exception. d) None of the above.

a) yes

Does Java support nesting classes? a) yes b) no

a) yes

Is this the correct way to create an object of the Animal class? Animal dog = new Animal( ); a) yes b) no c) maybe d) None of the above.

a) yes

What is a class in Java? a) A class in Java is used to create primitive data types. b) A class in Java is the user defined blue print with fields and methods. c) A class in Java is when you have tons of data that you do not know what to do with. It will allow you to be able to process the data to a file. d) None of the above.

b) A class in Java is the user defined blue print with fields and methods.

What is Abstraction in Java? a) Abstraction in Java is when you provide the implementation details to the user while hiding the functionality. b) Abstraction in Java is when you provide the functionality to the user while hiding the implementation details. c) Abstraction in Java does not exists, it is just a figment of your imagination. d) All of the above.

b) Abstraction in Java is when you provide the functionality to the user while hiding the implementation details.

What are Enums in Java? a) An Enum will allow you to create classes on the fly. b) An Enum in Java is a special type used to define collections of constants. c) Enums do not exist in Java. d) All of the above.

b) An Enum in Java is a special type used to define collections of constants.

What are constructors in Java? a) A constructor is a class that gets called when the project gets started. b) Constructors are special methods that are invoked when an object is created. c) A constructor is not a method, it is an instance of a class. d) None of the above.

b) Constructors are special methods that are invoked when an object is created.

What are the 4 pillars in Object-Oriented Programming? a) Encapsulation, Inheritance, Polymorphism, and Overriding b) Encapsulation, Inheritance, Polymorphism, and Abstraction c) Classes, Abstraction, Inheritance, and Overloading d) None of the above.

b) Encapsulation, Inheritance, Polymorphism, and Abstraction

What is inheritance in Java? a) Inheritance is when you have no classes in Java. b) Inheritance is the process that enables one class to acquire the properties (methods and variables) of another class. c) Inheritance in Java is the core to composition. d) None of the above.

b) Inheritance is the process that enables one class to acquire the properties (methods and variables) of another class.

A class can implement how many interfaces? a) It can only implement one interfaces per class. b) It can implement any number of interfaces. d) As long as the interface is declared as static you can have as many implementations as you need. d) All of the above.

b) It can implement any number of interfaces.

What are packages used for in Java? a) Packages are used to create inheritance. b) Packages are used to avoid name conflicts and to control access to classes. They are another form of encapsulation. c) You will need to use packages in Java to create arrays. d) None of the above.

b) Packages are used to avoid name conflicts and to control access to classes. They are another form of encapsulation.

Method overriding is also known as? a) Overriding numeric values. b) Run time polymorphism. c) inheritance d) None of the above.

b) Run time polymorphism.

What is the difference between the (==) operator and the equals( ) method? a) The (==) operator will do the same thing that the equals( ) method will do. b) The (==) operator will compare the reference of the object and the equals( ) method will actually check the value. c) The (++) operator will compare the value of the object and the equals( ) method will compare the value. d) None of the above.

b) The (==) operator will compare the reference of the object and the equals( ) method will actually check the value.

The HashSet class implements what interface? a) The HashSet class implements the list interface. b) The HashSet class implements the set interface. c) The HashSet class implements the map interface. d) None of the above.

b) The HashSet class implements the set interface.

In Java when creating a class the class name and what else has to be the same? a) Each method must reference the class name. b) The Java file which contains the class has to have the same name as the class. c) The class return type must be static. d) None of the above.

b) The Java file which contains the class has to have the same name as the class.

The LinkedHashSet class represents what? a) The LinkedHashSet method represents the LinkedList implementation of the set interface. It extends the HashSet class and implements the Set interface. b) The LinkedHashSet class represents the LinkedList implementation of the set interface. It extends the HashSet class and implements the Set interface. c) The LinkedHashSet class represents the LinkedList implementation of the list interface. It extends the HashSet class and implements the Set interface. d) None of the above.

b) The LinkedHashSet class represents the LinkedList implementation of the set interface. It extends the HashSet class and implements the Set interface.

What is the final key word used for when dealing with variables? a) The final key word will allow you to use the variables in a try catch block. b) The final keyword is used to make a variable constant. This means that it will be assigned only once. c) The final key word is only used with static variables. d) All of the above.

b) The final keyword is used to make a variable constant. This means that it will be assigned only once.

What are getters and setters used for in Java? a) They are only used for hiding your data. b) The getters and setters in Java are used to effectively protect your data. c) The getters and setters are only used for displaying your data. d) All of the above.

b) The getters and setters in Java are used to effectively protect your data.

What is the protected access modifier used for? a) The protected access modifier will only allow access within the same package. b) The protected access modifier will allow access within the same package and it will also allow access to the child class if it resides outside the package. c) The protected access modifier will allow access only within the class it resided in. d) None of the above.

b) The protected access modifier will allow access within the same package and it will also allow access to the child class if it resides outside the package.

What is the public access modifier in Java? a) The public access modifier only allows you access within the same package. b) The public access modifier in Java will allow you access to the data anywhere in the program. c) The public access modifier is only used in multiple inheritance. d) All of the above.

b) The public access modifier in Java will allow you access to the data anywhere in the program.

In Java Object-Oriented Programming, is a style that is intended to put programmers in the mindset of what? a) Mars b) The real world. c) Each line of code. d) None of the above.

b) The real world.

What is the return key word used for inside methods? a) The return keyword dose not exist. b) The return keyword is used to return a value inside a method. c) The return keyword can only be used within inheritance. d) All of the above.

b) The return keyword is used to return a value inside a method.

In method overloading the methods must have? a) The same name and the same parameters. b) The same name, but different parameters. c) Different parameters and a different name. d) None of the above.

b) The same name, but different parameters.

The set interface is part of the Java collection framework that cannot contain what? a) The set interface can contain duplicate values. b) The set interface cannot contain duplicate elements. c) All the above.

b) The set interface cannot contain duplicate elements.

If we have two objects with the same name and the equality testing returns false, why is this? a) This is because when you are checking multiple objects for equality, it will always return false because they all have the same memory location. b) This is because the two objects are referencing different memory locations. c) This is not true, all objects have the same memory address and this will return true. d) None of the above.

b) This is because the two objects are referencing different memory locations.

How do you call a method? a) To call a method, type its name plus the desired output. b) To call a method, type its name and then follow the name with a set of parentheses. c) To call a method, type its name along with square brackets. d) None of the above.

b) To call a method, type its name and then follow the name with a set of parentheses.

How do you create an object in Java? a) By declaring an object. b) You can create an object by instantiating a class. c) By using the static keyword. d) None of the above.

b) You can create an object by instantiating a class.

What is another name for method overloading? a) run-time polymorphism b) compile-time polymorphism c) data binding d) None of the above.

b) compile-time polymorphism

What is the output of this code? public class Main { static class Animal { String name; Animal (String n) { name = n; } } public static void main (String[ ] args) { Animal a1 = new Animal("Jack"); Animal a2 = new Animal("Jack"); System.out.println(a1 == a2); } } a) true b) false c) error d) None of the above.

b) false

In Object-Oriented programming each object has what three dimensions? a) house, blue print, methods b) identity, attributes, behavior c) name, attributes, identity d) None of the above

b) identity, attributes, behavior

Can an interface contain a constructor? a) yes b) no c) Yes, only when you have multiple interfaces. d) None of the above.

b) no

Can you override a static method? a) yes b) no c) Yes, but only when you have it in an inheritance. d) None of the above.

b) no

If you declare an inner class as private will you be able to access it outside of the class? a) yes b) no

b) no

Is Java a fully Object-Oriented Programming language? a) yes b) no c) maybe d) none of the above

b) no Because it has primitive data types.

What is Polymorphism? a) one implementation with different methods b) one method with different implementations c) each implementation with a different method d) All of the above.

b) one method with different implementations

Can you overload a static method? a) no b) yes c) Yes, but only when the method resides in a constructor. d) None of the above.

b) yes

Does the LinkedHashSet maintain the insertion order or permit null elements? a) no b) yes

b) yes

What is a method? a) A method is used to identify variables. b) A method is not a collection of statements that are grouped together to perform an operation. c) A method is a collection of statements that are grouped together to perform an operation. d) None of the above.

c) A method is a collection of statements that are grouped together to perform an operation.

What do Enums define? a) Enums will define only string variables. b) When defining an Enum, you will only be allowed to work with integer values. c) Enums define variables that represent member's of a fixed set. d) None of the above.

c) Enums define variables that represent member's of a fixed set.

In Java, what is an interface? a) In Java, an interface is a reference type and the fields are public final by default, the methods are abstract by default, and if you use the protected keyword you can have a method with an implementation. b) In Java, an interface is not a reference type and the fields are public final by default, the methods are abstract by default, and if you use the default keyword you can have a method with an implementation. c) In Java, an interface is a reference type and the fields are public final by default, the methods are abstract by default, and if you use the default keyword you can have a method with an implementation. d) None of the above.

c) In Java, an interface is a reference type and the fields are public final by default, the methods are abstract by default, and if you use the default keyword you can have a method with an implementation.

What are the classes in the set interface? a) Set<data-type> s1 = new HashArraySet<data-type>( ); Set<data-type> s2 = new LinkedHashSet<data-type>( ); Set<data-type> s3 = new TreeSet<data-type>( ); b) Set<data-type> s1 = new HashSet<data-type>( ); Set<data-type> s2 = new LinkedHashSet<data-type>( ); Set<data-type> s3 = new HashedTreeSet<data-type>( ); c) Set<data-type> s1 = new HashSet<data-type>( ); Set<data-type> s2 = new LinkedHashSet<data-type>( ); Set<data-type> s3 = new TreeSet<data-type>( );

c) Set<data-type> s1 = new HashSet<data-type>( ); Set<data-type> s2 = new LinkedHashSet<data-type>( ); Set<data-type> s3 = new TreeSet<data-type>( );

The HashSet will contain what? a) The HashSet will only contain numeric values. b) The HashSet will contain multiple classes. c) The HashSet will contain unique items. d) None of the above.

c) The HashSet will contain unique items.

What is the idea behind encapsulation? a) The idea behind encapsulation is to allow the data to be accessible any where in the program. b) To only be used in interfaces. c) The idea behind encapsulation is to ensure that the implementation details are not visible to users. This is also called data hiding. d) None of the above.

c) The idea behind encapsulation is to ensure that the implementation details are not visible to users. This is also called data hiding.

What is the private access modifier in Java? a) The private access modifier means that it will only be accessible within the main package. b) The private access modifier is a key word that is used to allow access anywhere in the program. c) The private access modifier in Java will bind the data to the class it resides in. Which means it is only accessible within that class. d) All of the above.

c) The private access modifier in Java will bind the data to the class it resides in. Which means it is only accessible within that class.

How do you create an inner class? a) You will have to use all the 4 pillars of Object-Oriented Programming to create an inner class. b) To create an inner class you will need to make the class private. c) You will simply write a class within a class. d) In creating an inner class, you will have to make the class abstract and final then you can create your inner class.

c) You will simply write a class within a class.

In the code below what are the fields and methods? public class Animal { int legs = 2; String name = "John"; public void sound( ) { System.out.println("Hello"); } } a) legs, name, and sound( ) b) void, public, Animal c) legs, name, sound d) All of the above

c) legs, name, sound

What key word do you use when you do not want any return? a) no-return b) static c) void d) All of the above

c) void


Conjuntos de estudio relacionados

Exam 4 3040 Comfort and Pain Management

View Set

Cool Workbook Who is your hero page 55

View Set

Chapter 1 - General Insurance Concepts: Idaho

View Set

sociology test 2 chapters 3,4, and 6

View Set

AP European History Napoleon Quiz

View Set

Chapter 5: Performance Appraisal

View Set