Skip to content

VIGNESH-T2005/java_oops_dsa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Classes and Objects
     
Classes :  
   Classes are template or blue print for creating an object and classes will consist of
        * attribute
        * constructors 
        * methods
general class structure 
public class classname{
    
    datatype attributename;     attribute 
    
    public classname(parameters){}  constructors
    
    public void methodname(parameters){} methods

}        
--------------------------------------------------------------------------------------------
Objects:
  objects are the real world entity that will act as instances of class with actual values 
  
  Scanner sc= new Scanner(System.in);   sc is the object
  
---------------------------------------------------------------------------------------------------
Attributes: 
   attributes are the instant variable that belong to the class and stores the data for each object 
       datatype attributename;
       
types in attribute:
    * primitive datatype attributes  - int number;
    * reference datatype attributes  - String name; string[] skills;
    * custom object attributes       - objname[] names;
 
--------------------------------------------------------------------------------------------------
constructors: 
   constructors are special methods that is used to initialize the objects and created with class name 
and has no return type this keyword is used to assign parameter to attributes  

constructors must be in class name 
       class age{
          public age(int age){}
       }
    
constructors has no return type 
         public class name(int data){}
         
constructors initialize using this keyword       
         this.atrributename=parameter name;       
       
--------------------------------------------------------------------------------------------------       
methods:
   methods/functions are the block of code that perform the specific tasks. this is behaviour/actions of of the object
and made the code reusable.
every method has separate stack memory 
types of methods        
       * with argument with return type 
       * with argument without return type
       * without argument with return type
       * without argument without return type
----------------------------------------------------------------------------------------------------------
OOPs in java:
   object oriented programming system is organising software that is based on object rather than function and loops.
object is  self contained unit that has attributes and methods

Four pillars of oops:
      * Encapsulation
      * Abstraction
      * Inheritance
      * Polymorphism
 
---------------------------------------------------------------------------------------------------------     
Encapsulation: 
   Its the process that involves wrapping the data attributes and methods all together in single class and restricting
direct access to the data variable from outside is called Encapsulation.
class demo{
   dataattributes;
   methods(){}
   main method{}
   }
-------------------------------------------------------------------------------------------------   
Inheritance :
  its the process of inheriting the properties of one classs to another class using the extends keywords
  super keyword is used to import parameters from parent class
  
  Types of Inheritance
  single
  multi
  hierarchial
  
-----------------------------------------------------------------------------------------------------------------
Abstraction:
  its the process of hiding the implementation process but it shows what work is done 
  
  two types of abstraction
     *absract class 
     *interface 
     
   abstract class : this is used by using abstract keyword before class and this cannot create object (instantiated) 
             *cannot be instantiated (cannot create obj with abstract class)
             *can have abstract methods no concrete
             *can have methods with body
   Abstract Class                    Interface
──────────────────                ──────────────────
Partial blueprint                 Pure contract
Can have constructors             No constructors
extends (one only)                implements (many)
abstract + concrete methods       abstract + default + static
Fields of any type                public static final only
IS-A relationship                 CAN-DO relationship        
-----------------------------------------------------------------------------------------------------              
Polymorphism :
     one method in many forms (poly-many morphism-forms) by different parameters creating in it
     
     two types of polymorphism
     *overloading
     *overriding
     
     overloading :
     creates many methods in same name but different parameters
     
     overriding :
     overriding the functions or properties of methods and it is done by inheriting the method
     
-------------------------------------------------------------------------------------------------------------------------------     
Collection:
         collection is a interface that is used to store data 
       
       
       

About

A collection of Java OOP programs and exercises I built while learning Object-Oriented Programming from scratch.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages