Publicité

FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Module_1_2.pptx

2 Jan 2023
Publicité

Contenu connexe

Publicité

FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Module_1_2.pptx

  1. Dr. Avadhesh Kumar Asst. Prof, SAS, VIT-AP Object Oriented Programming
  2.  Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior.  Every class has data field(data member) and method(function).
  3.  A Java object is an instance of a Java class. Each object has an identity, a behavior and a state.  The state of an object is stored in fields (variables), while methods (functions) display the object's behavior. Objects are created at runtime from templates, which are also known as classes.
  4.  A class is a template or blueprint from which objects are created. So, an object is the instance(result) of a class.
  5.  Originally, object-oriented programming was used most frequently for two major types of applications:  Computer simulations, which attempt to mimic real-world activities so that their processes can be improved or so that users can better understand how the real-world processes operate  Graphical user interfaces, or GUIs (pronounced “gooeys”), which allow users to interact with a program in a graphical environment
  6.  To understand object-oriented programming it requires grasping three basic concepts:  1. Encapsulation  2. Inheritance  3. Polymorphism
  7.  A method is a self-contained block of program code that carries out some action, similar to a procedure (function) in a procedural program (C program).  It is like a function in C program but it is associated some class.  For example, a Dog class might have methods for walking, eating.
  8.  In object-oriented classes, attributes and methods are encapsulated into objects.  Encapsulation is the enclosure of data and methods within an object.  Encapsulation allows you to treat all of an object’s methods and data as a single entity. Just as an actual dog contains all of its attributes and abilities, so would a program’s Dog object.
  9.  Encapsulation also refers to the concealment of an object’s data and methods from outside sources.  Concealing data is sometimes called information hiding.  Encapsulation lets you hide specific object attributes and methods from outside sources and provides the security that keeps data and methods safe from inadvertent(undesired) changes.
  10.  An important feature of object-oriented program design is inheritance—the ability to create classes that share the attributes and methods of existing classes, but with more specific features.  For example, Automobile is a class, and all Automobile objects share many traits and abilities. Convertible is a class that inherits from the Automobile class; a Convertible is a type of Automobile that has and can do everything a “plain” Automobile does—but with an added ability
  11.  A final important concept in object-oriented terminology is polymorphism.  Literally, polymorphism means “many forms”—it describes the feature of languages that allows the same word or symbol to be interpreted correctly in different situations based on the context.  For example, although the classes Automobile, Sailboat, and Airplane all inherit from Vehicle, turn and stop methods work differently for instances of those classes.
  12.  It is a Java standard, although not a requirement, to begin class identifiers with an uppercaseletter and employ other uppercase letters as needed to improve readability.  (By contrast, method identifiers, like println(), conventionally begin with a lowercase letter.)  The stylethat joins words in which each word begins with an uppercase letter is called Pascal casing, or sometimes upper camel casing. You should follow established conventions for Java so  your programs will be easy for other programmers to interpret and follow.
  13.  To create a Scanner object and connect it to the System.in object, you write a statement similar to the following:  Scanner inputDevice = new Scanner(System.in);
  14.  A main() method executes automatically when you run a program, but other methods do not execute simply because you place them within a class—they must be called.  The method header is the first line of a method. It contains the following:  Optional access specifiers  A return type  An identifier  Parentheses
  15.  It is a special type of method which is used to initialize the object.  Every time an object is created using the new() keyword, at least one constructor is called.  It calls a default constructor if there is no constructor available in the class. In such case, Java compiler provides a default constructor by default.
  16.  Constructor name must be the same as its class name  There are two types of constructors in Java:  1. Default constructor (no-arg constructor)  2. Parameterized constructor
  17.  The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or class.  We can change the access level of fields, constructors, methods, and class by applying the access modifier on it.
  18.  Private: The access level of a private modifier is only within the class. It cannot be accessed from outside the class.  Default: The access level of a default modifier is only within the package. It cannot be accessed from outside the package. If you do not specify any access level, it will be the default.  Protected: The access level of a protected modifier is within the package and outside the package through child class. If you do not make the child class, it cannot be accessed from outside the package.  Public: The access level of a public modifier is everywhere. It can be accessed from within the class, outside the class, within the package and outside the package
Publicité