Java – OOPS

Java – Introduction to OOPS

Application: Program Elements: Program is a set of instructions.Every Program consists, Syntax Examples   datatype identity = value;   String name = “amar”; int age = 23; double salary = 35000.00; boolean married = false;   Syntax Example returntype identity(arguments){      body;} int add(int a, int b){      int c = a+b;      return c;}

Java – OOP Features

Introduction to Object oriented programming: Note: We implement Object-Oriented functionality using Classes and Objects Class: Class contains variables and methods. Java application is a collection of classes Syntax Example class ClassName{            Variables ;               &            Methods ;} class Account{            long num;            String name;            double balance;            void withdraw(){               logic;            }            void deposit(){               logic;            }} …

Java – OOP Features Read More »

Java – Class Members

Class Members: Variables: Variable stores information of class(object).We store information in java using 4 types of variables Blocks: Static Block: Defining a block using static-keyword. JVM invokes static block when class execution starts. static{            statements;} Instance Block: Defining a block without static-keyword. JVM invokes instance block every time when object creates. {            statements;} Methods: Static …

Java – Class Members Read More »

Java – main() method

Static Members: Static main() method: public static void main(String[] args)Orpublic static void main(String args[]) Program to display Hello World on Console: public class Code{            public static void main(String[] args){                        System.out.println(“Hello World”);            }} Class without main(): We can define class without main() method but we cannot run that class. public class Code{            void fun(){                        System.out.println(“fun…”);            }} …

Java – main() method Read More »

Java – Static Block

Static block: class Pro{            static{                        System.out.println(“Static block”);            }            public static void main(String args[]){                        System.out.println(“Main method”);            }} Output:           Static Block        Main method

Java – Static Methods

Method: Syntax Example returntype identity(arguments){            statements;} int add(int a, int b){            int c=a+b;            return c;} Classification of Methods: Based on taking input and returning output, methods are classified into 4 types. Method Definition: Method definition consists logic to perform the task. It is a block. Method Call: Method Call is used to invoke the method …

Java – Static Methods Read More »

Java – Static Variables

Static Variable: class Bank{      static String bankName = “AXIS”;} Note: We always process the data (perform operations on variables) using methods. Getter and Setter Methods: class Code{            static int a;            static void setA(int a){                        Code.a = a;            }            static int getA(){                        return Code.a;            }            public static void main(String[] args){                        Code.setA(10);                        System.out.println(“A val : ” + …

Java – Static Variables Read More »

Java – Instance Members

Instance Members: Object Creation of a Class in java: Syntax:           ClassName ref = new ClassName(); Example:        Employee emp = new Employee(); Constructor: class Employee{            Employee()            {                        System.out.println(“Constructor”);            }} We must invoke the constructor in Object creation process: class Employee{            Employee()            {                        System.out.println(“Object created”);            }            public static void main(String args[])            {                        Employee emp = new Employee();            …

Java – Instance Members Read More »

Java – Instance Methods

Instance Method: No arguments and No return values method: class Code{            public static void main(String[] args) {                        Code obj = new Code();                        obj.fun();            }            void fun(){                        System.out.println(“fun”);            }} With arguments and No return values method: class Code{            static void main(String[] args) {                        Code obj = new Code();                        obj.isEven(4);                        obj.isEven(13);            }            static void isEven(int n){                        if(n%2==0)                        …

Java – Instance Methods Read More »

Scroll to Top