Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Advanced Java Programming

Introduction
• Object – represent entities in the real world
• Eg:- Person, things, Bank AC, Emp-record
• Classes – describe the behaviour of the object
• See about How to define and use class and objects
General of a Class
• Class – contains data members and methods
• Methods – are used to access the data
• The General Form of a Class is
• Class Classname
• {
• type1 dataname1;
• type2 dataname2;
• .
• typeN datanameN;
• returntype1 methodName1(argumentList1)
• {
• }
• returntype2 methodName2(argumentList2)
• {
• }
• returntypeN methodNameN(argumentListN)
• {
• }
• }
Explanation
• Class – is the keyword
• Classname - is the name of the class
• - the rule is similar to the identifiers
• Dataname1,Dataname2..DatanameN - are the data
members.
• It means variables – are declared in the beginning of the class
• Data members are called as fields
• Data methods are declared followed by the data members
• The Data member has three parts
• (i) return type
• (ii) method name
• (iii) argument list
• The commonly used classes are System and Math
• Predefined classes are started with Upper Case
• Objects and methods are start with Lower Case (eg:- out-object and println()-method)
• Eg:-
• Rectangle
• {
• Int length;
• Int width;
• Int rectangleArea()
• {
• return(length * width);
• }
• }
• A class variable can be accessed by any other method in the class
• In the example length and width are the variable
• The method rectangeArea() is used with in the method housewhitewashcost()
• Eg:-
• ….
• Int housewhitewashcost()
• {
• return rectangleArea() * 15;
• }
• 15 – means Rs.15 per square feet

You might also like