CS 3230 Flashcards

1
Q

== and .equals()

A

Both equals() method and the == operator are used to compare two objects in Java. == is an operator and equals() is method. … In simple words, == checks if both objects point to the same memory location whereas . equals() evaluates to the comparison of values in the objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

public, protected, private

A

Broadly speaking, public means everyone is allowed to access, private means that only members of the same class are allowed to access, and protected means that members of subclasses are also allowed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Instance variables

A

An instance variable is a variable which is declared in a class but outside of constructors, methods, or blocks. Instance variables are created when an object is instantiated, and are accessible to all the constructors, methods, or blocks in the class. Access modifiers can be given to the instance variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Calling static methods

A

A static method can be called directly from the class, without having to create an instance of the class. A static method can only access static variables; it cannot access instance variables. Since the static method refers to the class, the syntax to call or refer to a static method is: class name. method name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Method overriding

A

Method overriding, in object-oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. It allows for a specific type of polymorphism (subtyping).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Polymorphism

A

In programming languages and type theory, polymorphism is the provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Access private data members of a superclass

A

To access the private members of the superclass you need to use setter and getter methods and call them using the subclass object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Constructor chaining

A

Constructor chaining is the process of calling one constructor from another constructor with respect to current object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Interfaces

A

In Java, an interface is an abstract type that contains a collection of methods and constant variables. It is one of the core concepts in Java and is used to achieve abstraction, polymorphism and multiple inheritances. We can implement an interface in a Java class by using the implements keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Determining what methods may called through an interface-typed variable

A

Methods inside interface must not be static, final, native or strictfp. All variables declared inside interface are implicitly public, static and final. All methods declared inside interfaces are implicitly public and abstract, even if you don’t use public or abstract keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The impact of implementing an interface

A

When a class implements an interface, you can think of the class as signing a contract, agreeing to perform the specific behaviors of the interface. If a class does not perform all the behaviors of the interface, the class must declare itself as abstract

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

wait(), notify(), and notifyAll()

A

The wait() method causes the current thread to wait until another thread invokes the notify() or notifyAll() methods for that object. The notify() method wakes up a single thread that is waiting on that object’s monitor. The notifyAll() method wakes up all threads that are waiting on that object’s monitor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

start() versus run()

A

So what is the difference between the start and run method? Main difference is that when program calls start() method a new Thread is created and code inside run() method is executed in new Thread while if you call run() method directly no new Thread is created and code inside run() will execute on current Thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

monitors

A

The monitor is one of the ways to achieve Process synchronization. The monitor is supported by programming languages to achieve mutual exclusion between processes. … Only one process at a time can execute code inside monitors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Synchronized methods

A

Synchronized method is used to lock an object for any shared resource. When a thread invokes a synchronized method, it automatically acquires the lock for that object and releases it when the thread completes its task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Thread.sleep()

A

What is thread sleep ()?
Image result for Thread.sleep()
Thread. sleep() method can be used to pause the execution of current thread for specified time in milliseconds.

17
Q

What is the difference between “Upcasting” and “Downcasting”

A

Upcasting is casting to a supertype, while downcasting is casting to a subtype