SlideShare una empresa de Scribd logo
1 de 21
PRESENTED BY:-
SURESH MOHTA
A class is a blueprint of a set of objects that have a common
behaviour. Based on the blueprint, actual objects are created. In
simple words, a class is defines an outline, based on which actual
objects are created. A class can contain fields and methods to
describe the behaviour of an object. In general, class declarations
can include these components, in order:
 Modifiers : A class can be public or has default access .
1) Class name: The name should begin with a initial letter
(capitalized by convention).
2) Superclass(if any): The name of the class’s parent (superclass), if
any, preceded by the keyword extends. A class can only extend
(subclass) one parent.
3) Interfaces(if any): A comma-separated list of interfaces
implemented by the class, if any, preceded by the keyword
implements. A class can implement more than one interface.
4) Body: The class body is surrounded by braces, { }.
 Class is a user defined data type
 Variables and functions can be created with in a class
 Syntax:
class classname[extends superclassname]
{
[fields declaration];
[method declaration];
}
 Example:
class Area
{
int length;
int breadth;
}
A class is a blueprint from which individual objects are created.
A class can contain any of the following variable types.
 Local variables − Variables defined inside methods, constructors or
blocks are called local variables. The variable will be declared and
initialized within the method and the variable will be destroyed when
the method has completed.
 Instance variables − Instance variables are variables within a class
but outside any method. These variables are initialized when the
class is instantiated. Instance variables can be accessed from inside
any method, constructor or blocks of that particular class.
 Class variables − Class variables are variables declared within a
class, outside any method, with the static keyword.
A class can have any number of methods to access the value of various
kinds of methods. In the example, barking(), hungry() and sleeping() are
methods.
public class Dog {
String breed;
int age;
String color;
void barking() {
}
void hungry() {
}
void sleeping() {
}
}
 It is a basic unit of Object Oriented Programming and
represents the real life entities. A typical Java
program creates many objects, which as you know,
interact by invoking methods. An object consists of :
 State : It is represented by attributes of an object. It
also reflects the properties of an object.
 Behaviour : It is represented by methods of an object.
It also reflects the response of an object with other
objects.
 Identity : It gives a unique name to an object and
enables one object to interact with other objects.
 Example of an object: dog
class Student
{
int rollno;
String name;
void insertRecord(int r, String n)
{
rollno=r;
name=n;
}
void displayInformation(){System.out.println(rollno+" "+name);}
}
class TestStudent4
{
public static void main(String args[])
{
Student s1=new Student();
Student s2=new Student();
s1.insertRecord(29,“Sumit");
s2.insertRecord(30,“Suresh");
s1.displayInformation();
s2.displayInformation();
}
}
Output: 29 Sumit
30 Suresh
 A method is a named piece of code within a
program and executes when it is called from
another section of code.
 Now we will see how to create a methods with
or without return values, invoke a method with
or without parameters, and apply method
abstraction in the program design.
 In java, without methods class has no LIFE.
 Methods are essential for manipulating the
data in program.
 Methods are the interface or communications between program
components.
 In java, a method must be defined before it is used anywhere in the
program.
SYNTAX: Example:
Type methodname(parameter list) public class Cube
{ {
method body; int length;
} int breadth;
int height;
Public int getVolume()
{
return(length*breadth*height);
} }
Note: type of the value method return.-it can be void,int,double etc.
 If a class have multiple methods by same name but
different parameters, it is known as Method
Overloading. If we have to perform only one
operation, having same name of the methods
increases the readability of the program.
 Method Overloading is also known as Static
Polymorphism.
 Static Polymorphism is also known as compile time
binding or early binding.
 Static Binding happens at compile time. Method
Overloading is an example of static binding where
binding of method call to its definition happens at
compile time.
 If subclass (child class) has the same method
as declared in the parent class, it is known as
Method Overriding in Java.
 In other words, if subclass provides the
specific implementation of the method that
has been provided by one of its parent class,
it is known as Method Overriding.
ADVANTAGE : The main advantage of method
overriding is that the class can give its own
specific implementation to a inherited
method without even modifying the parent
class(base class).
OVERLOADING-
class sum{
void add(int a, int b){
System.out.println(“sum of two
=”+(a+b)); }
void add(int a, int b, int c){
System.out.println(“sum of
three=“+(a+b+c)); }
}
class Polymorphism {
public static void main(String
args[]) {
Sum s=new Sum();
s.add(10,15); s.add(10,20,30);}
}
o/p:- Sum of two=25
Sum of three=60
OVERRIDING-
class A{
void fun(){
System.out.println(“HELLO”); } }
class B extends A{
void fun() {
System.out.println(“HI”); } }
class c {
public static void main(String
args[]) }
B ob=new B();
ob.fun();
A ob1=new A();
Ob1.fun(); }
}
o/p:- HI
HELLO
A command-line argument is the
information that follows the name of the program
on the command line of the operating system. The
java command-line argument is an argument that
is passed at the time of running of the java
program.
The arguments passed from the
console can be received in the java program and it
can be used as an input.
Command line argument provides a
convenient way to check the behaviour of the
program for the different values. We can pass N
(1,2,3 and so on) numbers of arguments from the
command prompt.
To access the command-line
arguments inside a Java program is quite easy.
They are stored as strings in the String array
passed to main().
Command line argument is used to
pass the argument at the time when we write the
command to run any program.
The following program of command line
argument displays only one argument that
it is called with-
class Commandline{
public static void main(String args[]){
System.out.println(“First argument is :”+
args[0]);
}
}
compile by > javac CommandLine.java
run by > java CommandLine suresh
OUTPUT:
First argument is: suresh
The following program displays all of the
command line arguments that is called with-
class CommandLine {
public static void main(String args[]) {
for(int i=0;i<args.length;i++) {
System.out.println(“args[“+ i +”]:“+ args[i]);
}
}
}
 // Try executing this:
 $java CommandLine this is a command line
10
 Output
 args[0]:this
args[1]: is
args[2]: a
args[3]: command
args[4]: line
args[5]: 10
Basic concept of class, method , command line-argument

Más contenido relacionado

La actualidad más candente

encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaMOHIT AGARWAL
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear ASHNA nadhm
 
Main method in java
Main method in javaMain method in java
Main method in javaHitesh Kumar
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywordsmanish kumar
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In JavaCharthaGaglani
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.netsuraj pandey
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptmanish kumar
 
Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Bhanwar Singh Meena
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismEduardo Bergavera
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 

La actualidad más candente (20)

encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear
 
Main method in java
Main method in javaMain method in java
Main method in java
 
11. java methods
11. java methods11. java methods
11. java methods
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Computer programming 2 Lesson 15
Computer programming 2  Lesson 15Computer programming 2  Lesson 15
Computer programming 2 Lesson 15
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.net
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
OOP java
OOP javaOOP java
OOP java
 
Abstract method
Abstract methodAbstract method
Abstract method
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
 
Hemajava
HemajavaHemajava
Hemajava
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 

Similar a Basic concept of class, method , command line-argument

Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)Khaled Anaqwa
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Ayes Chinmay
 
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
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsMaryo Manjaruni
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 

Similar a Basic concept of class, method , command line-argument (20)

Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Lecture 8 Library classes
Lecture 8 Library classesLecture 8 Library classes
Lecture 8 Library classes
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Chap11
Chap11Chap11
Chap11
 
C# program structure
C# program structureC# program structure
C# program structure
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Core java oop
Core java oopCore java oop
Core java oop
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
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
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Java mcq
Java mcqJava mcq
Java mcq
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 

Último

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 

Último (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Basic concept of class, method , command line-argument

  • 2. A class is a blueprint of a set of objects that have a common behaviour. Based on the blueprint, actual objects are created. In simple words, a class is defines an outline, based on which actual objects are created. A class can contain fields and methods to describe the behaviour of an object. In general, class declarations can include these components, in order:  Modifiers : A class can be public or has default access . 1) Class name: The name should begin with a initial letter (capitalized by convention). 2) Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent. 3) Interfaces(if any): A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface. 4) Body: The class body is surrounded by braces, { }.
  • 3.  Class is a user defined data type  Variables and functions can be created with in a class  Syntax: class classname[extends superclassname] { [fields declaration]; [method declaration]; }  Example: class Area { int length; int breadth; }
  • 4. A class is a blueprint from which individual objects are created. A class can contain any of the following variable types.  Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.  Instance variables − Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.  Class variables − Class variables are variables declared within a class, outside any method, with the static keyword. A class can have any number of methods to access the value of various kinds of methods. In the example, barking(), hungry() and sleeping() are methods.
  • 5. public class Dog { String breed; int age; String color; void barking() { } void hungry() { } void sleeping() { } }
  • 6.  It is a basic unit of Object Oriented Programming and represents the real life entities. A typical Java program creates many objects, which as you know, interact by invoking methods. An object consists of :  State : It is represented by attributes of an object. It also reflects the properties of an object.  Behaviour : It is represented by methods of an object. It also reflects the response of an object with other objects.  Identity : It gives a unique name to an object and enables one object to interact with other objects.  Example of an object: dog
  • 7.
  • 8. class Student { int rollno; String name; void insertRecord(int r, String n) { rollno=r; name=n; } void displayInformation(){System.out.println(rollno+" "+name);} } class TestStudent4 { public static void main(String args[]) {
  • 9. Student s1=new Student(); Student s2=new Student(); s1.insertRecord(29,“Sumit"); s2.insertRecord(30,“Suresh"); s1.displayInformation(); s2.displayInformation(); } } Output: 29 Sumit 30 Suresh
  • 10.  A method is a named piece of code within a program and executes when it is called from another section of code.  Now we will see how to create a methods with or without return values, invoke a method with or without parameters, and apply method abstraction in the program design.  In java, without methods class has no LIFE.  Methods are essential for manipulating the data in program.
  • 11.  Methods are the interface or communications between program components.  In java, a method must be defined before it is used anywhere in the program. SYNTAX: Example: Type methodname(parameter list) public class Cube { { method body; int length; } int breadth; int height; Public int getVolume() { return(length*breadth*height); } } Note: type of the value method return.-it can be void,int,double etc.
  • 12.  If a class have multiple methods by same name but different parameters, it is known as Method Overloading. If we have to perform only one operation, having same name of the methods increases the readability of the program.  Method Overloading is also known as Static Polymorphism.  Static Polymorphism is also known as compile time binding or early binding.  Static Binding happens at compile time. Method Overloading is an example of static binding where binding of method call to its definition happens at compile time.
  • 13.  If subclass (child class) has the same method as declared in the parent class, it is known as Method Overriding in Java.  In other words, if subclass provides the specific implementation of the method that has been provided by one of its parent class, it is known as Method Overriding. ADVANTAGE : The main advantage of method overriding is that the class can give its own specific implementation to a inherited method without even modifying the parent class(base class).
  • 14. OVERLOADING- class sum{ void add(int a, int b){ System.out.println(“sum of two =”+(a+b)); } void add(int a, int b, int c){ System.out.println(“sum of three=“+(a+b+c)); } } class Polymorphism { public static void main(String args[]) { Sum s=new Sum(); s.add(10,15); s.add(10,20,30);} } o/p:- Sum of two=25 Sum of three=60 OVERRIDING- class A{ void fun(){ System.out.println(“HELLO”); } } class B extends A{ void fun() { System.out.println(“HI”); } } class c { public static void main(String args[]) } B ob=new B(); ob.fun(); A ob1=new A(); Ob1.fun(); } } o/p:- HI HELLO
  • 15. A command-line argument is the information that follows the name of the program on the command line of the operating system. The java command-line argument is an argument that is passed at the time of running of the java program. The arguments passed from the console can be received in the java program and it can be used as an input.
  • 16. Command line argument provides a convenient way to check the behaviour of the program for the different values. We can pass N (1,2,3 and so on) numbers of arguments from the command prompt. To access the command-line arguments inside a Java program is quite easy. They are stored as strings in the String array passed to main(). Command line argument is used to pass the argument at the time when we write the command to run any program.
  • 17. The following program of command line argument displays only one argument that it is called with- class Commandline{ public static void main(String args[]){ System.out.println(“First argument is :”+ args[0]); } }
  • 18. compile by > javac CommandLine.java run by > java CommandLine suresh OUTPUT: First argument is: suresh
  • 19. The following program displays all of the command line arguments that is called with- class CommandLine { public static void main(String args[]) { for(int i=0;i<args.length;i++) { System.out.println(“args[“+ i +”]:“+ args[i]); } } }
  • 20.  // Try executing this:  $java CommandLine this is a command line 10  Output  args[0]:this args[1]: is args[2]: a args[3]: command args[4]: line args[5]: 10