Java Final + Haskell

Java Final + Haskell

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

(True/False) You can override a private method defined in a superclass.

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 (35)

Section 1

(35 cards)

(True/False) You can override a private method defined in a superclass.

Front

False - You can only override accessible instance methods.

Back

What is an unbounded wildcard?

Front

? is an unbounded wildcard

Back

What keyword is used to define a subclass?

Front

Extends

Back

How does a subclass invoke its superclass's constructor?

Front

By using the super() keyword.

Back

How do you create a lock object?

Front

ReentrantLock()

Back

How do you decide whether a variable or method should be an instance or static?

Front

Instance variables or methods are ones that are dependent on a specific instance of a class. For example, every circle has its own radius, so the radius is dependent on a specific circle. Therefore, radius is an instance variable of the Circle class. None of the methods in the Math class, such as random, pow, sin, and cos, are dependent on a specific instance, therefore they are static methods. An example: public class F { int i; static String s; } F f = new F(); System.out.println(f.i); //valid System.out.println(f.s); //valid System.out.println(F.i); //invalid System.out.println(F.s); //valid

Back

Can a generic class have multiple generic parameters?

Front

Yes

Back

What is a lower-bounded wildcard?

Front

? super T is a lower bounded wildcard

Back

How can multiple threads run simultaneously in a single-processor system?

Front

Most of the time, the CPU is idle, for example, the CPU is doing nothing while the user enters data - it is practical for multiple threads to share the CPU time in single-processor systems.

Back

How do you set a priority for a thread?

Front

setPriority() method

Back

What is the default value of a boolean variable?

Front

False

Back

How do you define a class?

Front

Class is a template, which defines an object's data fields and methods. Additionally, a class provides a special type of methods called constructors, which are invoked to create a new object. The syntax to define a class is: public class ClassName {}

Back

How do you acquire a lock and release a lock?

Front

To acquire the lock, invoke its lock() method. To release a lock, invoke its unlock() method.

Back

How do you invoke an overridden superclass method from a subclass?

Front

Use super().method() or super.method(args).

Back

How do you create an object?

Front

An object is an instance of a class. It can create by using the "new" operator and the dot operator. The syntax to create an object is: new ClassName(); For example, ClassName object = new ClassName();

Back

Why is multithreading needed?

Front

Multithreading can make your program more responsive and interactive, and enhance performance. Multithreading is needed for many situations, such as animation and client/server computing.

Back

Describe the relationship between an object and its defining class.

Front

An object represents an entity. It is one particular instance of that type of entity. A class defines the structure and behaviors of all entities of a given type and an object is an instance of a class. For example, String s = ""; String is the class and s is the object.

Back

What is multiple inheritance? Does Java support multiple inheritance?

Front

Multiple inheritance allows a subclass to extend multiple classes. Java does not support this behavior.

Back

When will a class have a default constructor?

Front

A class has a default constructor only if the class does not define any constructor. A class normally provides a constructor without arguments. Default constructor is provided automatically only if no constructors are explicitly defined in the class. It can call some other constructor in the same class, or it can use super() to explicitly call some particular constructor in the super class.

Back

How can you catch an exception?

Front

To catch an exception, you write a try-catch statement, for example: try { // code } catch (Exception ex) { // process exception }

Back

(True/False) A subclass is a subset of a superclass.

Front

False - A class that extends or derives from another class is called a subclass. A subclass is also called a derived class. A subclass that is derived from a class is called a super class. A superclass is also called the base class or parent class.

Back

(True/False) When invoking a constructor from a subclass, its superclass's no-arg constructor is always invoked.

Front

False - If a subclass's constructor is explicitly invokes a superclass's constructor, the superclass's no-arg constructor is not invoked.

Back

What is a thread?

Front

A thread is a wrapper object for a runnable object for executing a runnable task.

Back

What are the differences between constructors and methods?

Front

Constructors do not have a return type, while methods may have a return type. Constructors do not have a return statement in their body, while methods may have a return statement. Constructors must have the same name as the class name, while methods are not allowed to have the same name as the class name. Constructors are used to initialize the instance variables of an object, while methods are not involved in object creation. Constructors must have either a call to another constructor in the same class (using this), or a call to the super class constructor. If the first line is neither of these, the compiler inserts a call to the parameterless super class constructor. Methods do not have such provisions. The only way a constructor can be invoked is from within another constructor. A method can be called from another method.

Back

How do you create a condition on a lock?

Front

A condition on a lock can be created by using lock.newCondition().

Back

What does the JVM do when an exception occurs?

Front

When an exception occurs, Java searches for a handler in the catch clause.

Back

What is a bounded wildcard?

Front

? extends T is a bounded wildcard

Back

What is the default priority for a thread?

Front

Thread.NORM_PRIORITY(5).

Back

How do you declare an object's reference variable.

Front

A reference variable can hold the reference of an object, but when we call any method by using a reference variable, we always only all those methods which type of object we create. The syntax to declare a reference variable is: ClassName referenceName;

Back

How do you declare a generic type in a class?

Front

To declare a generic type for a class, place the generic type after the class name, such as GenericStack<E>. To declare a generic type for a method, place the generic type for the method return type, such as <E> void max (E obj1, E obj2).

Back

(True/False) You can override a static method defined in a superclass.

Front

False - You can only override accessible instance methods.

Back

What are the await(), signal(), and signallAll() methods for?

Front

await() method causes the current thread to wait until the condition is signaled. signal() method wakes up one waiting thread. signallAll() method wakes up all waiting threads.

Back

What is a runnable object?

Front

An instance of Runnable is a runnable object.

Back

What is single inheritance?

Front

Single inheritance allows a subclass to extend only one superclass.

Back

How do you explicitly invoke a superclass's constructor from a subclass?

Front

Use super() or super(args). This must be the first statement in the constructor in the subclass.

Back