SlideShare a Scribd company logo
1 of 15
Static Keyword:-
By default all the member of class are instance member. To
associate with it class member we used static key word
Instance member- its represents attribute and behavior of object
Class member- it represents attribute and behavior of class.
Simple def-
we can call attributes & methods of a class without
creating objects.
attributes = variables(int a) + Object variable (C1 o; )
methods = Constructor + functions + Distructors in C++
static data members not duplicate for each Object,
act like a global variable.
for declaring global variables in C & C++, we have
concept of pre processor or declare variable outside
the main method
but in java we have only static declaration for global
variables.
static data members can access with class name, object
& direct also but non static members only access
with objects.
* static can be variables, methods, objects, class
& can be block also.
* any concept use with class name that is static.
static variable:- static variable will have a single copy per
class
classname.var - static variable
ex-
Font.BOLD;
static method:- when u want to call a method using class name
instead of using object of class
classname.methodname() - static method
Integer.parseInt()
static object
classname.objectname - static object
System.out
static block: whenever u want to execute a code before execution
of main method u can write a code using static block
static {} - static block.
Qus- how to display welcome msd without using psvm-
class Hello
{
static
{
System.out.println("Ha Ha Ha Ha He He He ");
System.exit(0);
}
}
static class -
Inner class can be static, if inner class is static,
then we can create the inner class object in Outer
class p s v m without using Outer class object - direct.
*** outer class can't be static.
public class Sta2
{
static class Inner
{
void disp()
{
System.out.println("I m inside inner class disp");
}
}
public static void main(String[] args)
{
Inner o = new Inner();
o.disp();
}
}
KeyWord
/*
final keyword - final that means final - fixed - can't changed.
like const in C & C++.
final can be variables, methods & can be class also.
=> if variable is final then can't reassign any value.
=> if method is final then can't override in Child class.
=> if class is final then can't extends - can't inherit.
- final variable example.
final String dsn = "jdbc:odbc:erp"; - now U can't change it */
class F1
{
final int a = 1000;
void disp()
{
// a = 10; // error - can't assign any value to a final var a
System.out.println("a = "+a);
}
public static void main(String[] args)
{
F1 o = new F1();
o.disp();
}
}
/*
super keyword - it is use for calling the super class variables ,
methods & Constructors.
super means one step up - just inherited class
- super class variable calling
*/
class S
{
int a = 1000;
}
class S1 extends S // class S1 inherit the prop of class S
{
int a = 100;
void disp()
{
int a = 10;
System.out.println("a = "+a); // local a - 10
System.out.println("a = "+this.a); // currentobject.a -
global a - 100
System.out.println("a = "+super.a); // super class a
calling - 1000
}
public static void main(String[] args)
{
S1 o = new S1();
o.disp();
}}
this operator - it's return the ref of current object. like this
pointer
in C++. it is for -
* where we want to refer the current object.
=>* which is the object variable & which is the argument/local
variable then
we can use this operator.
* to call the current class Constructor(one Constructor to another
Constructor
calling without using new Operator), then we can use this
operator.
(imp. for interview) , concept only supported by - Java , VC++ &
C#.
*/
class Th2
{
int a = 100 ;
void disp()
{
int a = 10;
System.out.printf("a = %d n",a); // local - a - 10
System.out.printf("a = %d n",this.a); // currentobject.a ,
global a - 100
}
public static void main(String aa[])
{
Th2 o = new Th2();
o.disp(); // a = 100
}
}
super keyword - it is use for calling the super class variables ,
methods & Constructors.
super means one step up - just inherited class
- super class variable calling
*/
class S
{
int a = 1000;
}
class S1 extends S // class S1 inherit the prop of class S
{
int a = 100;
void disp()
{
int a = 10;
System.out.println("a = "+a); // local a - 10
System.out.println("a = "+this.a); // currentobject.a -
global a - 100
System.out.println("a = "+super.a); // super class a
calling - 1000
}
public static void main(String[] args)
{
S1 o = new S1();
o.disp();
}}
OPPS Concept:-
Object
Class
Encapsulation
Inheritance
Abstraction
Polymorphism
All pre define type are object
All user define type are object
Qus= Why java is not 100% OOPS
Ans:-1-everything in java is not consider as a Object. There are
primitive data type such as int , char , Booleans are not object
2- all feature of oops language is not fully supported by java Ex:-
Multiple inheritance
Object - it is a kind of variable that can hold the ref of a class.
Object is the direct ref.
C1 o; - in C++
C1 o = new C1(); - in JAVA
o.disp(); - C1 class disp.
Class:- it is collection of object that share similar attribute, operators or
relasionship Class can exist without an object but reverse can not
Constructor:- is the method, used for initializing the attribute of class.
Attribute= variables + object variable
Constructor has some rules & prop -
rules -
=> Constructor name & class name must be same.
=> Constructor no return any value that means not void.
prop -
=> every class has one Constructor.
=> if user does not define any Constructor in a class then default
Constructor created.
=> if class has any own Constructor then default Constructor is not
created.
=> if one class has more then one Constructor then that is called Constructor
overloading.
Incapsulation:- Encapsulation is the technique of making the fields in a class
private and providing access to the fields via public methods. If a field is declared
private, it cannot be accessed by anyone outside the class, thereby hiding the fields
within the class. For this reason, encapsulation is also referred to as data hiding
The main benefit of encapsulation is the ability to modify our implemented code
without breaking the code of others who use our code. With this feature
Encapsulation gives maintainability, flexibility and extensibility to our code.
/* EncapTest.java */
public class EncapTest{
private String name;
private String idNum;
private int age;
public int getAge(){
return age;
}
public String getName(){
return name;
}
public String getIdNum(){
return idNum;
}
public void setAge( int newAge){
age = newAge;
}
public void setName(String newName){
name = newName;
}
public void setIdNum( String newId){
idNum = newId;
}
}
/////////////
/RunEncap.java */
public class RunEncap{
public static void main(String args[]){
EncapTest encap = new EncapTest();
encap.setName("James");
encap.setAge(20);
encap.setIdNum("12343ms");
System.out.print("Name : " + encap.getName()+
" Age : "+ encap.getAge());
}
}
Inheritance:- is the process by which object of one class acquire the properties of
object of another class, a class that is inherited is called a super class and the class
that dose the inheriting is called subclass. It is done by using keyword extends
two most common reason reasons to use inheritance are
1- To promote code reuse
2- To use polymorphism
class A {
void disp(){
System.out.println(" i am inside A display");
}}
class B extends A {
/* void disp(){
System.out.println(" i am inside B display");
}
*/
public static void main(String[] args) {
B o =new B();
o.disp();
} }
// Overriding:- if parent and child class has one methods with same name & and
same sign( argument and return type) that is called method overriding.
class types in java –
concrete class abstract class
* only concrete methods * concrete + abstract methods.
* can create object & inherit * can't create instance, inherit only.
abstract class - if one class has one more abstract methods then that
is called an abstract class.
Q- we can create an abstract class without any abstract methods or not?.
ans - yes , just declare as abstract. but can't create the direct instance.
adv - abstract classes used for memory management, memory for methods
provided by the abstract class.
condition -
* all abstract methods of an abstract class must be override in child
class else child class is also a kind of abstract class.
future - abstract classes in used when need hierarchy of class like tree structure
Limitation:- only single inheritance example:- one class can extends only one
abstract class
For multiple inheritance we use interface
interface - it is a kind of pure abstract class.
// to create an simple abstract class.
abstract class Calc
{
void sum(int a,int b)
{
System.out.println("Sum is = "+(a+b));
}
abstract void sub(int a,int b);
}
save with Calc.java
//class inherit with an abstract class
class MyCalc extends Calc
{
void sub(int a,int b) // method of Calc
{ System.out.println("Sub is = "+(a-b)); }
public static void main(String aa[]) {
MyCalc o = new MyCalc();
o.sum(100,20);
o.sub(100,20);
} }
Diffrence b/w abstract and interface:-
abstract class Interface
concrete + abstract methods. only absract methods
using abstract classes java * using
interfaces java support
support only single inheritance
using interfaces java support
multiple inheritance also.
Constructor – Yes Constructor – no
* all attributes default - normal
Ex:- int a = 10
all attributes default - final
& static. Ex:- final static int a = 10;
default access modifier – default default is public.
extends keyword. implements keyword.
class to class - extends
interface to interface - extends
interface to class - implements.
Interface:- interface is collection of implicit abstract methods and static final
data member
Adv:- interface are used for memory management ,
Prop:- support multiple inheritance
Conditions:- all interface methods must be override in child class else child class
is a kind of abstract class .
default access modifier in interface is public
variable declare must be initialize
ex:- int a; - error;
int a = 10; valid
// interface can't have
interface Prob
{
// void disp(){} // error
// Prob(){} // error
// int a; // error
// private void disp(); // error
// protected void disp(); // error
// final void disp(); // error
// default in interface
abstract void disp();
public abstract void disp1();
final int a = 10;
static final int b = 10;
public final int v = 10;
public static final int c = 10;
static int d = 10;
}
/////////////////
interface Calc
{
void sum(int a,int b);
void sub(int a,int b);
}
////
interface Calc1
{
void multi(int a,int b);
}
// multiple inheritance with interface
class MyCalc1 implements Calc,Calc1
{
public void sum(int a,int b) // method of Calc
{
System.out.println("Sum is = "+(a+b));
}
public void sub(int a,int b) // method of Calc
{
System.out.println("Sub is = "+(a-b));
}
public void multi(int a,int b) // method of Calc1
{
System.out.println("Multi is = "+(a*b));
}
public static void main(String aa[])
{
MyCalc1 o = new MyCalc1();
o.sum(100,20);
o.sub(100,20);
o.multi(100,20);
}
}
Polymorphism: can be implemented in java language in the form of
multiple methods having same name
Type:-
1- Compile Time:- is done using method overloading , its also
called Early binding.
2- Run Time Polymorphism :is done using inheritance. Its also called
Late binding
// user define Constructor with Constructor overloading
class C2
{
int a,b;
C2() // no argument passing Constructor
{
a = b = 0;
}
C2(int x) // one argument passing Constructor
{
a = b = x;
}
C2(int x,int y) // two argument passing Constructor
{
a = x;
b = y;
}
void disp()
{
System.out.printf("a = %d , b = %dn",a,b);
}
public static void main(String aa[])
{
C2 o1 = new C2(); // no argument passing Constructor calling
C2 o2 = new C2(100); // one argument passing Constructor
calling
C2 o3 = new C2(10,20); // two argument passing Constructor
calling
o1.disp(); // a = 0 , b = 0
o2.disp(); // a = 100 , b = 100
o3.disp(); // a = 10 , b = 20
}
}

More Related Content

What's hot

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsFALLEE31188
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in javaMahmoud Ali
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectOUM SAOKOSAL
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++ThamizhselviKrishnam
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in javaRaja Sekhar
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - InheritanceOum Saokosal
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statementmanish kumar
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 

What's hot (20)

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in java
 
Java basic
Java basicJava basic
Java basic
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
C++ And Object in lecture3
C++  And Object in lecture3C++  And Object in lecture3
C++ And Object in lecture3
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
 
Oop
OopOop
Oop
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - Inheritance
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 

Viewers also liked

Viewers also liked (20)

final year project center in Coimbatore
final year project center in Coimbatorefinal year project center in Coimbatore
final year project center in Coimbatore
 
final year project coimbatore
final year project coimbatorefinal year project coimbatore
final year project coimbatore
 
All consuming fire
All consuming fireAll consuming fire
All consuming fire
 
E-star 7
E-star 7E-star 7
E-star 7
 
1
11
1
 
MISE - Reti di impresa per l'artigianato digitale
MISE - Reti di impresa per l'artigianato digitaleMISE - Reti di impresa per l'artigianato digitale
MISE - Reti di impresa per l'artigianato digitale
 
Alabare
AlabareAlabare
Alabare
 
Adm 327 protocolo para secretarias
Adm 327   protocolo para secretariasAdm 327   protocolo para secretarias
Adm 327 protocolo para secretarias
 
Ultimate Medical Academy Deans List
Ultimate Medical Academy Deans ListUltimate Medical Academy Deans List
Ultimate Medical Academy Deans List
 
Савинов Максим. Локационная система сопровождения
Савинов Максим. Локационная система сопровожденияСавинов Максим. Локационная система сопровождения
Савинов Максим. Локационная система сопровождения
 
T-Bosiet_I
T-Bosiet_IT-Bosiet_I
T-Bosiet_I
 
cap 11 al 22
cap 11 al 22cap 11 al 22
cap 11 al 22
 
Holy spirit rain down
Holy spirit rain downHoly spirit rain down
Holy spirit rain down
 
Jvm
JvmJvm
Jvm
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
 
El Proyecto Educativo Institucional en la Escuela ccesa007
El Proyecto Educativo Institucional en la Escuela  ccesa007El Proyecto Educativo Institucional en la Escuela  ccesa007
El Proyecto Educativo Institucional en la Escuela ccesa007
 
Diapo literaria 31
Diapo literaria 31Diapo literaria 31
Diapo literaria 31
 
Catheterisation
CatheterisationCatheterisation
Catheterisation
 
ENFOQUE DE LA CORPOREIDAD
ENFOQUE DE LA CORPOREIDADENFOQUE DE LA CORPOREIDAD
ENFOQUE DE LA CORPOREIDAD
 
Diapo literaria 35
Diapo literaria 35Diapo literaria 35
Diapo literaria 35
 

Similar to Static Keyword and OOPs Concepts

UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)Durga Devi
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
Keyword of java
Keyword of javaKeyword of java
Keyword of javaJani Harsh
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.pptEmanAsem4
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance SlidesAhsan Raja
 

Similar to Static Keyword and OOPs Concepts (20)

OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
Java02
Java02Java02
Java02
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
Only oop
Only oopOnly oop
Only oop
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance Slides
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 

More from Kamlesh Singh

More from Kamlesh Singh (7)

ReactJS
ReactJSReactJS
ReactJS
 
Angular js book
Angular js bookAngular js book
Angular js book
 
Smart machines
Smart machinesSmart machines
Smart machines
 
Spring roo-docs
Spring roo-docsSpring roo-docs
Spring roo-docs
 
Database Oracle Basic
Database Oracle BasicDatabase Oracle Basic
Database Oracle Basic
 
Oops Concept Java
Oops Concept JavaOops Concept Java
Oops Concept Java
 
Java Basic day-1
Java Basic day-1Java Basic day-1
Java Basic day-1
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Static Keyword and OOPs Concepts

  • 1. Static Keyword:- By default all the member of class are instance member. To associate with it class member we used static key word Instance member- its represents attribute and behavior of object Class member- it represents attribute and behavior of class. Simple def- we can call attributes & methods of a class without creating objects. attributes = variables(int a) + Object variable (C1 o; ) methods = Constructor + functions + Distructors in C++ static data members not duplicate for each Object, act like a global variable. for declaring global variables in C & C++, we have concept of pre processor or declare variable outside the main method but in java we have only static declaration for global variables. static data members can access with class name, object & direct also but non static members only access with objects. * static can be variables, methods, objects, class & can be block also. * any concept use with class name that is static. static variable:- static variable will have a single copy per class classname.var - static variable ex- Font.BOLD; static method:- when u want to call a method using class name instead of using object of class classname.methodname() - static method Integer.parseInt() static object classname.objectname - static object System.out
  • 2. static block: whenever u want to execute a code before execution of main method u can write a code using static block static {} - static block. Qus- how to display welcome msd without using psvm- class Hello { static { System.out.println("Ha Ha Ha Ha He He He "); System.exit(0); } } static class - Inner class can be static, if inner class is static, then we can create the inner class object in Outer class p s v m without using Outer class object - direct. *** outer class can't be static. public class Sta2 { static class Inner { void disp() { System.out.println("I m inside inner class disp"); } } public static void main(String[] args) { Inner o = new Inner(); o.disp(); } } KeyWord /* final keyword - final that means final - fixed - can't changed. like const in C & C++. final can be variables, methods & can be class also. => if variable is final then can't reassign any value. => if method is final then can't override in Child class. => if class is final then can't extends - can't inherit. - final variable example. final String dsn = "jdbc:odbc:erp"; - now U can't change it */ class F1 {
  • 3. final int a = 1000; void disp() { // a = 10; // error - can't assign any value to a final var a System.out.println("a = "+a); } public static void main(String[] args) { F1 o = new F1(); o.disp(); } } /* super keyword - it is use for calling the super class variables , methods & Constructors. super means one step up - just inherited class - super class variable calling */ class S { int a = 1000; } class S1 extends S // class S1 inherit the prop of class S { int a = 100; void disp() { int a = 10; System.out.println("a = "+a); // local a - 10 System.out.println("a = "+this.a); // currentobject.a - global a - 100 System.out.println("a = "+super.a); // super class a calling - 1000 } public static void main(String[] args) { S1 o = new S1(); o.disp(); }} this operator - it's return the ref of current object. like this pointer in C++. it is for - * where we want to refer the current object. =>* which is the object variable & which is the argument/local variable then we can use this operator. * to call the current class Constructor(one Constructor to another Constructor calling without using new Operator), then we can use this operator.
  • 4. (imp. for interview) , concept only supported by - Java , VC++ & C#. */ class Th2 { int a = 100 ; void disp() { int a = 10; System.out.printf("a = %d n",a); // local - a - 10 System.out.printf("a = %d n",this.a); // currentobject.a , global a - 100 } public static void main(String aa[]) { Th2 o = new Th2(); o.disp(); // a = 100 } } super keyword - it is use for calling the super class variables , methods & Constructors. super means one step up - just inherited class - super class variable calling */ class S { int a = 1000; } class S1 extends S // class S1 inherit the prop of class S { int a = 100; void disp() { int a = 10; System.out.println("a = "+a); // local a - 10 System.out.println("a = "+this.a); // currentobject.a - global a - 100 System.out.println("a = "+super.a); // super class a calling - 1000 } public static void main(String[] args) { S1 o = new S1(); o.disp(); }}
  • 5.
  • 6. OPPS Concept:- Object Class Encapsulation Inheritance Abstraction Polymorphism All pre define type are object All user define type are object Qus= Why java is not 100% OOPS Ans:-1-everything in java is not consider as a Object. There are primitive data type such as int , char , Booleans are not object 2- all feature of oops language is not fully supported by java Ex:- Multiple inheritance Object - it is a kind of variable that can hold the ref of a class. Object is the direct ref. C1 o; - in C++ C1 o = new C1(); - in JAVA o.disp(); - C1 class disp. Class:- it is collection of object that share similar attribute, operators or relasionship Class can exist without an object but reverse can not Constructor:- is the method, used for initializing the attribute of class. Attribute= variables + object variable Constructor has some rules & prop - rules - => Constructor name & class name must be same.
  • 7. => Constructor no return any value that means not void. prop - => every class has one Constructor. => if user does not define any Constructor in a class then default Constructor created. => if class has any own Constructor then default Constructor is not created. => if one class has more then one Constructor then that is called Constructor overloading. Incapsulation:- Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code. /* EncapTest.java */ public class EncapTest{ private String name; private String idNum; private int age; public int getAge(){ return age; } public String getName(){ return name; } public String getIdNum(){ return idNum; } public void setAge( int newAge){ age = newAge; } public void setName(String newName){ name = newName;
  • 8. } public void setIdNum( String newId){ idNum = newId; } } ///////////// /RunEncap.java */ public class RunEncap{ public static void main(String args[]){ EncapTest encap = new EncapTest(); encap.setName("James"); encap.setAge(20); encap.setIdNum("12343ms"); System.out.print("Name : " + encap.getName()+ " Age : "+ encap.getAge()); } }
  • 9. Inheritance:- is the process by which object of one class acquire the properties of object of another class, a class that is inherited is called a super class and the class that dose the inheriting is called subclass. It is done by using keyword extends two most common reason reasons to use inheritance are 1- To promote code reuse 2- To use polymorphism class A { void disp(){ System.out.println(" i am inside A display"); }} class B extends A { /* void disp(){ System.out.println(" i am inside B display"); } */ public static void main(String[] args) { B o =new B(); o.disp(); } }
  • 10. // Overriding:- if parent and child class has one methods with same name & and same sign( argument and return type) that is called method overriding. class types in java – concrete class abstract class * only concrete methods * concrete + abstract methods. * can create object & inherit * can't create instance, inherit only. abstract class - if one class has one more abstract methods then that is called an abstract class. Q- we can create an abstract class without any abstract methods or not?. ans - yes , just declare as abstract. but can't create the direct instance. adv - abstract classes used for memory management, memory for methods provided by the abstract class.
  • 11. condition - * all abstract methods of an abstract class must be override in child class else child class is also a kind of abstract class. future - abstract classes in used when need hierarchy of class like tree structure Limitation:- only single inheritance example:- one class can extends only one abstract class For multiple inheritance we use interface interface - it is a kind of pure abstract class. // to create an simple abstract class. abstract class Calc { void sum(int a,int b) { System.out.println("Sum is = "+(a+b)); } abstract void sub(int a,int b); } save with Calc.java
  • 12. //class inherit with an abstract class class MyCalc extends Calc { void sub(int a,int b) // method of Calc { System.out.println("Sub is = "+(a-b)); } public static void main(String aa[]) { MyCalc o = new MyCalc(); o.sum(100,20); o.sub(100,20); } } Diffrence b/w abstract and interface:- abstract class Interface concrete + abstract methods. only absract methods using abstract classes java * using interfaces java support support only single inheritance using interfaces java support multiple inheritance also. Constructor – Yes Constructor – no * all attributes default - normal Ex:- int a = 10 all attributes default - final & static. Ex:- final static int a = 10; default access modifier – default default is public.
  • 13. extends keyword. implements keyword. class to class - extends interface to interface - extends interface to class - implements. Interface:- interface is collection of implicit abstract methods and static final data member Adv:- interface are used for memory management , Prop:- support multiple inheritance Conditions:- all interface methods must be override in child class else child class is a kind of abstract class . default access modifier in interface is public variable declare must be initialize ex:- int a; - error; int a = 10; valid // interface can't have interface Prob
  • 14. { // void disp(){} // error // Prob(){} // error // int a; // error // private void disp(); // error // protected void disp(); // error // final void disp(); // error // default in interface abstract void disp(); public abstract void disp1(); final int a = 10; static final int b = 10; public final int v = 10; public static final int c = 10; static int d = 10; } ///////////////// interface Calc { void sum(int a,int b); void sub(int a,int b); } //// interface Calc1 { void multi(int a,int b); } // multiple inheritance with interface class MyCalc1 implements Calc,Calc1 { public void sum(int a,int b) // method of Calc { System.out.println("Sum is = "+(a+b)); } public void sub(int a,int b) // method of Calc { System.out.println("Sub is = "+(a-b)); } public void multi(int a,int b) // method of Calc1 { System.out.println("Multi is = "+(a*b)); } public static void main(String aa[]) { MyCalc1 o = new MyCalc1(); o.sum(100,20); o.sub(100,20); o.multi(100,20); } }
  • 15. Polymorphism: can be implemented in java language in the form of multiple methods having same name Type:- 1- Compile Time:- is done using method overloading , its also called Early binding. 2- Run Time Polymorphism :is done using inheritance. Its also called Late binding // user define Constructor with Constructor overloading class C2 { int a,b; C2() // no argument passing Constructor { a = b = 0; } C2(int x) // one argument passing Constructor { a = b = x; } C2(int x,int y) // two argument passing Constructor { a = x; b = y; } void disp() { System.out.printf("a = %d , b = %dn",a,b); } public static void main(String aa[]) { C2 o1 = new C2(); // no argument passing Constructor calling C2 o2 = new C2(100); // one argument passing Constructor calling C2 o3 = new C2(10,20); // two argument passing Constructor calling o1.disp(); // a = 0 , b = 0 o2.disp(); // a = 100 , b = 100 o3.disp(); // a = 10 , b = 20 } }