Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.

Similar presentations


Presentation on theme: "What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you."— Presentation transcript:

1 What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you use the ‘ class declaration ’ to create many objects of that ‘ class type ’

2 A java class ‘class’ is a keyword every class has a name and body a class can contain methods, member variables and constructors class declaration can be preceded by a modifier – ‘public’ or ‘private’ every class object needs to be instantiated with the ‘ new ’ operator

3 every java ‘class’ is placed in its own file when java source file (given by.java ) is compiled, a.class file gets created in the bin directory of your project The file with the.class extension in the bin directory is the bytecode for the class.

4 Declaring a primitive data type: int a; char c; byte b; Instantiating a class object: MyClass mc= new MyClass();

5 Access modifiers ‘public’ —the field is accessible from all classes. ‘private’ —the field is accessible only within its own class. access modifiers can be applied on both member variables and methods of a class

6 Difference between ‘class’ and primitive data type you cannot invoke a method on a primitive data type you need to instantiate a class variable after you declare it instantiation is done with new operator new is a keyword here

7 Difference between a static method and normal method static methods are invoked on the class name normal methods are invoked on the class object

8 More on variables

9 More on primitive data types - Initialization

10 Using ‘String’ objects


Download ppt "What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you."

Similar presentations


Ads by Google