53511784-41908952-Java-OOP - Classes Interfaces And...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
1 © Virtusa Corporation   Confidential Classes, Interfaces And Packages Objectives After completing this chapter, the student will be able to Explain Java classes Explain Java objects Declare and define simple Java classes Create objects of Java classes and do manipulation on those objects by invoking class methods Explain class constructors and finalizers Explain access modifiers and the difference between different access modifiers
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 © Virtusa Corporation   Confidential Objectives: Continued. .. Explain class inheritance Explain the difference between method overloading and method overriding Explain abstract classes, interfaces and interface implementation Explain Java packages Explain CLASSPATH environment variable and set it to suit his/her requirement Write programs to create Java packages Explain the usage of import and package statements Write Java programs using previously created packages Explain the important packages in Java API
Background image of page 2
3 © Virtusa Corporation   Confidential Declaring Classes The syntax for declaring classes in Java is as follows: class identifier { classBody }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 © Virtusa Corporation   Confidential Java Class Declaration An Example: class ExampleClass { char cc; int ii; double dd; void exampleMethod1() { System.out.println(“Hello World”); } void exampleMethod2() { System.out.println(“Hello CMC Ltd”); } }
Background image of page 4
5 © Virtusa Corporation   Confidential The new Operator In Java a declaration ExampleClass ec will simply state what type of variable ec will be. No object is created and hence no memory allocation In Java Objects are created using the new operator as shown below ExampleClass ec; ec=new ExampleClass(); OR ExampleClass ec=new ExampleClass();
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 © Virtusa Corporation   Confidential Invoking Class Methods In Java class methods or class member functions are invoked using class objects as shown below ExampleClass ec=new ExampleClass(); ec.exampleMethod1(); ec.exampleMethod2();
Background image of page 6
7 © Virtusa Corporation   Confidential An Example Java Program public class Example1 { public static void main(String argv[]) { ExampleClass ec=new ExampleClass(); ec.exampleMethod1(); ec.exampleMethod2(); } } class ExampleClass { char ch; int ii; double dd;
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8 © Virtusa Corporation   Confidential Example Program: Continued. .. void exampleMethod1( ) { System.out.println("Hello World"); } void exampleMethod2( ) { System.out.println("Hello CMC Ltd"); } } On compiling and running this program will print an output as shown below; Hello World Hello CMC Ltd
Background image of page 8
9 © Virtusa Corporation   Confidential Constructors Constructors are special methods you can implement in your classes. Constructors allow you to perform initialization of
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 66

53511784-41908952-Java-OOP - Classes Interfaces And...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online