OOP Flashcards
ways to copy the values of one object into another in Java:
- By constructor
- By assigning the values of one object into another
- By clone () method of Object class
Is the mechanism of wrapping up of data and code action on the
methods together as a single unit.
Encapsulation
We can create classes inside a package and import it in our main class so that we can use that class in our program
true
It should start with the uppercase letter.
It should be an adjective such as
Runnable, Remote, ActionListener.
Use appropriate words, instead of
acronyms.
Interface
Usage of Java super Keyword:
- super can be used to refer immediate parent class instance variable.
- super can be used to invoke immediate parent class method.
- super() can be used to invoke immediate parent class constructor.
Rules for using of Static Variables:
- Variables or methods belong to class rather than to any particular instance.
- A static method cannot access a non-static variable of a class nor can directly invoke non-static method.
- Static members can be applied without creating or referencing an instance of the class.
- A static variable will be shared by all instances of that class which will result in only one copy.
means that this method doesn’t return any value.
void
Java follows camel-case syntax for naming the class, interface, method,
and variable.
If the name is combined with two words, the second word will start with
uppercase letter always such as actionPerformed(), firstName,
ActionEvent, ActionListener, etc.
CamelCase
is used to denote constants. It can be used with variables,
methods, and classes.
Final keyword
is a method of out that can be used to print a line.
To achieve encapsulation in Java:
- Declare the variables of a class as private.
- Provide public setter and getter methods to modify and view the variables values.
3 ways to initialize object:
Initialization through reference
Initialization through method
Initialization through a constructor
If the reference variable of Parent class refers to the object of Child class, it is known as
Upcasting
Importing Packages:
- Importing Specific Class
ex: import packagename.classname - Import Whole Package
ex: import packagename.*
uses variables to define data fields and methods to define
actions, and provides methods of a special type, known as
constructors, which are invoked to create a new object.
class
is a pre-defined class that Java provides us and it holds some
useful methods and variables.
System
is represented by data fields with their current values.
The state of an object
It should be a lowercase letter such as
java, lang.
If the name contains multiple words, it
should be separated by dots (.) such as
java.util, java.lang.
Package
means that you can run this method without creating an instance
of Main.
static
is a way of thinking about and structuring a
program’s functionality.
programming paradigm
Static keyword is unacceptable to the following:
- Class
- Constructor
- Local inner classes
- Inner class methods
- Instance variables
- Local Variables
- Interfaces
Rules in Creating Java Constructor:
- Constructor name must be the same as its class name
- A Constructor must have no explicit return type.
- A Java constructor cannot be abstract, static, final, and
synchronized.
means that anyone can access it.
public
specifies the accessibility or scope of a field,
method, constructor, or class.
access modifiers
two ways to overload the method in java:
Method Overloading: changing no. of arguments
Method Overloading: changing data type of arguments
is a block of code which only runs when it is called.
method
It should start with a lowercase letter
such as id, name.
It should not start with the special
characters like & (ampersand), $
(dollar), _ (underscore).
If the name contains multiple words,
start it with the lowercase letter
followed by an uppercase letter such as
firstName, lastName.
Avoid using one-character variables
such as x, y, z.
Variable
- The process by which objects can acquire the properties of
objects of other class. - Provides reusability, like adding additional features to an existing
class without modifying it.
Inheritance
is used to create an instance of the class. In other
words, it instantiates a class by allocating memory for a new object and
returning a reference to that memory.
New Keyword
Information can be passed to methods as parameter. act as
variables inside the method.
Parameters or Arguments
- Refers to the ability to process objects differently depending on
their data type or class. - The ability to redefine methods to derived classes.
- Request for an operation can be made without knowing which
specific method should be invoked. - A task performed into different ways.
Polymorphism