0% found this document useful (0 votes)
4 views

Classes and Objects

GSEB 12th commerce Computer Chapter classes and objects PPT

Uploaded by

sayonijain1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Classes and Objects

GSEB 12th commerce Computer Chapter classes and objects PPT

Uploaded by

sayonijain1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

CLASSES AND OBJECTS

 Class contains data and program code(functions)


 Ex: class student
{
int sub1,sub2,total;
void setmarks()
{
sub1=10,sub2=20;
}
}
OBJECTS:
 Objects are real life entities. Objects consists of state,
behaviour, identity.
class student
{
student s1;
s1=new student();
}
 Local Variables : variables inside the block or methods.
 Instance variables : variables within the class and outside
the method.
 Class variables : variables within the class and outside the
method, with static keyword.
 Polymorphism: One in many forms(Method Overloading)

Different forms of methods with same name.


Ex: int max(int x, int y)
int max(int x, int y, int z)
CONSTRUCTORS:
 It is a kind of method which is invoked when a new object is
created.
 It has the same name as class name.
Visibility Modifiers(Access Modifiers)
The Four P’s of protection are public, protected, private,
package.
Default-Package
Public-accessed by all
Protected-accessed only by methods with friend
Private-accessed only within the class or method
COMPOSITION AND AGGREGATION
Has-a relationship between classes.
Ex: class person , he has name address
ACCESSOR AND MUTATOR
METHODS:
 Accessor Methods : Allows Private data to be used by
others.
 Getter Methods: If we want other methods to read only
the data value.
 Mutator Methods : Allows modification to the private
data by the users.
 Setter Methods: If we want other methods to modify
the data value.
ARRAY:
 An array is a collection of similar type of elements.
 1D(List of Items), 2D(Matrix Rows and Columns)

Ex: int marks[]………..declare array object


marks= new int[5]………create array object
int marks[]={10,20,30}
2D: int marks[][]= new int[5][3]
 public class Array
 {
 public static void main(String[] args)
 {
 int [] array = {1, 2, 3, 4, 5};
 for (int element: array)
 {
 System.out.println(element);
 }
 }
 }
STRING:
 Sequence of characters. Enclosed in “ “
 To store string two classes String and StringBuffer.

Calendar class and Date class are provided in


java.util.package
GregorianCalendar is the subclass of Calendar class

You might also like