Section 1

Preview this deck

If a parent class has no zero-argument constructor, what is the NAME of the first method the child must call?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (71)

Section 1

(50 cards)

If a parent class has no zero-argument constructor, what is the NAME of the first method the child must call?

Front

super()

Back

If a parent class has an abstract method, what does this mean for the child?

Front

A class derived from the abstract class must implement all those methods that are declared as abstract in the parent class. If a child does not implement all the abstract methods of abstract parent class, then the child class must need to be declared abstract as well.

Back

What interface does an object need to implement to be used in a TreeSet?

Front

All elements inserted into the TreeSet must implement the Comparable interface.

Back

Which data structure you should choose if you want to store data that will be accessed with their index?

Front

Array or ArrayList. Not HashMap or LinkedList

Back

Subclasses can access protected instance variables from the parent class

Front

True

Back

Write a function that takes in a List of Integers and returns the sum:

Front

Back

A private instance variable must have both a getter and a setter.

Front

False

Back

A class has to have a constructor.

Front

Java provides a default parameterless constructor. Ok with the answer being either True or False as long as that is the explanation.

Back

A class can have a private constructor.

Front

True

Back

Write a method that copies all elements of an ArrayList of String into an array of Strings.

Front

Back

We always implement an abstract class and extend an interface.

Front

False. We always extend an abstract class and implement an interface.

Back

Which data structure should you choose if you want to remove existing data.

Front

HashMap or LinkedList Not Array and ArrayList

Back

A child class has to implement any abstract methods declared in the parent class.

Front

True

Back

An abstract class can extend another abstract class.

Front

True

Back

We can call a method in a class if:

Front

We're inside the class; we instantiate the object and the method is public; the method is static

Back

Can an interface have abstract methods?

Front

Yes

Back

Does a class with an abstract method need to be declared as abstract?

Front

Yes

Back

A class has been declared by saying public class Exam{ // there is some stuff here } Inside this class the word super cannot be used since it does not extend any class.

Front

False

Back

It is possible to have the two methods public String make(String s) and public int make(String s) in the same class.

Front

False

Back

A Finally block will get invoke whether the exception is thrown or not

Front

True

Back

Arrays in Java are dynamically sized.

Front

False

Back

What is the default implementation of the equals(Object o) method?

Front

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true)(dress equivalence of the obj).

Back

Can we store doubles in an array that is declared as integers?

Front

No

Back

An abstract class can implement an interface.

Front

True.

Back

You already have Student class. Declare a hashmap that can map studentkeys to Student objects.

Front

HashMap<String, Student> mapping; or HashMap<String, Student> mapping = new HashMap<String, Student>();

Back

Can we store integers in an array that is declared as doubles

Front

Yes but you can't go the other way

Back

int a = (int)"4" can this compile?

Front

No

Back

An abstract class will always have an abstract method.

Front

False. A class can be made abstract just to make sure that you never create an instance of the class itself but only of subclasses.

Back

What does the word collision mean with respect to hashing?

Front

When we put objects into a hashtable, it is possible that different objects (by the equals() method) might have the same hashcode. This is called a collision.

Back

A class can implement 3 interfaces.

Front

True

Back

Every class needs a main method.

Front

False

Back

Declare an integer array that can hold 100 numbers.

Front

int[] arr = new int[100];

Back

A catch block can exist without a try block.

Front

False

Back

Write a function that takes in a String and returns its reverse. (Hint: use the charAt(int index) function)

Front

Back

What is an example of a static method other than the ones in the Math class that Java provides to you?

Front

Integer.parseInt Math.abs or Math.sqrt don't count Integer.compare Double.Max_Value Double.toString

Back

Can an interface have non-abstract methods?

Front

No

Back

A class must have a constructor.

Front

True

Back

What can be stored in a single Java array?

Front

Primitive types; strings; objects; but it can only do one type it can't do two types ex. ints and doubles not allowed

Back

What is the significance of the @Before tag in a JUnit Test?

Front

The code marked @Before will be executed before each test. This is useful for writing many tests that need similar objects or need to run similar code before they run. accepted The code marked @Before is executed before each test, while @BeforeClass runs once before the entire test fixture. If your test class has ten tests, @Before code will be executed ten times, but @BeforeClass will be executed only once. If you only need setup once, you use @BeforeClass when multiple tests need to share the same computationally expensive setup code. You can move code from @BeforeClass into @Before, but your test run may take longer. Note that the code marked @BeforeClass is run as static initializer, therefore it will run before the class instance of your test fixture is created.

Back

5/2==2?

Front

False

Back

Static variables are always public, i.e. can be accessed outside of class.

Front

True

Back

A class can extend from 2 parent classes.

Front

False

Back

What interface does an object need to implement to be used in a TreeMap?

Front

Map

Back

Java does not allow a method with the same signature in a subclass, as a method in the super class

Front

False. That is basically what overloading is.

Back

A single JButton can have more than 1 ActionListener

Front

False

Back

Convert the string "50" into the number 50.

Front

Integer.parseInt("50");

Back

Doing string1.equals(string2) is the same as doing string2.equals(string1)

Front

False

Back

Which data structures implement the Collection interface?

Front

Array; LinkedList; or Set Not HashMap

Back

An ArrayList can contain primitive data types

Front

True

Back

You can have two overloaded methods with a di erence only in the return type.

Front

False. To overload the methods you have to have a di erence either in name or argument types or number of arguments

Back

Section 2

(21 cards)

public void printMessage(int myInt) { System.out.println("my message is = " + i); } Is void printMessage(int randomInt) a valid overloaded method?

Front

False

Back

Suppose we have the following method: public void printMessage(int myInt) { System.out.println("my message is = " + i); } Is void printMessaget(double myDouble) a valid overloaded method?

Front

True

Back

What are some ways of handling errors in java?

Front

Try/Catch or Throw

Back

Suppose you have the following method; public void draw(int i, double f) { ... } Is public void draw(double f, int i) a valid overloaded method?

Front

True

Back

Two methods can have the same signature

Front

False

Back

We should only declare but not implement methods in an abstract class.

Front

False. This is true for interface, but we allow function implementation in abstract classes.

Back

A child class can inherit from more than one parent classes.

Front

False

Back

Can a method throw more than 1 errors?

Front

Yes

Back

Java allows programmers to define two or more functions with the same name and in the same scope. This is called

Front

Overloading

Back

We can have a non-abstract class that contains an abstract method.

Front

False. If any class has an abstract method, the class becomes abstract.

Back

We always extend an abstract class and implement an interface.

Front

True

Back

We can instantiate an interface.

Front

False. Interface only contain function definitions but not function implementations. Thus we cannot instantiate an interface.

Back

The method signature includes the method's return type, the method's name and parameter type.

Front

False

Back

An interface can implement another interface.

Front

False. An interface can extend another interface.

Back

Java allows programmers to define two or more functions with the same name and in a different scope. This is called

Front

Overwriting

Back

A java class can only inherit from 1 superclass, thus we need multilevel inheritance to achieve multiple inheritance

Front

False. It is true that a class can only extend 1 superclass, but it can always inherit from multiple interfaces.

Back

Java does not allow methods of the same name.

Front

False

Back

We can instantiate an abstract class.

Front

False. We cannot create an object to an abstract class as an abstract class may contain abstract unimplemented methods.

Back

A class can implement more than one interface.

Front

True

Back

In a subclass' constructor, the first thing we want to call is always super().

Front

False. We call super() only if we want to call the superclass' constructor.

Back

Suppose we have the following method: public void printMessage(int myInt) { System.out.println("my message = " + i); } Is String printMessage(int myInt) a valid overloaded method?

Front

False

Back