












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This lecture is delivered by Prem Vikas at Jaypee Institute of Information Technology University for discussing following points of Java Network Programming: Classes, Objects, Public, Private, Protected, Inner, Classes, Overloading, Constructors, Methods
Typology: Slides
1 / 20
This page cannot be seen from the preview
Don't miss anything!
Public, Private, Protected,default Packages Importing classes Inner Classes Creating instances of classes Constructors Overloading Constructors Methods Abstract ,final,native,synchronize Parameters (by value or by reference) Scope of variables Casting and conversion Method overloading
Introduction examples
package cont…
package my2Dgraphics;
public class Circle{
}
package bscis.semester0.xyz
public class Circle{
}
package cont…
Package name becomes part of class identity A class name when written with its package name is termed as its fully qualified name Example my2Dgraphics.Circle bscis.semester0.xyz.Circle Directory structure reflected by two class files will be outputpath/my2Dgraphics/Circle.class Outputpath/bscis/semester0/xyz/Circls.class
Import statement should placed before start of a class Example import javax.swings.JOptionPane; Import javax.swings.*;
Primitive or reference variable in the class that is not part of any method in the class
public private protected Default access (Package access)
The keyword public is written before the member to make it public Methods or variables declared are directly accessible to other classes and objects through the object-no access restriction
The keyword private is written before the member to make it private Methods or variables declared private are not directly accessible to any other class or object
controlling access….
The keyword protected is written to make a member protected A protected member is accessible to other classes with in the package Outside the package only child classes can access a protected member Not accessible to non-inherited classes outside the package
When no access specifieris used before a class member the access of that member function or variable is default or package Such members are accessible to other classes within the package Such members are not accessible to other classes outside the package
controlling access….examples
package temp;
public class Test{
private int x; public static void main (String s[]){ Test t=new Test(); t.x=90; //Error } }
controlling access….examples
public class Test{ protected int x; public static void main (String s[]){ Test t=new Test(); t.x=90; //Accessd } }
package temp; public class Test2{ Test t=new Test(); public void methodx ( ){ t.x=120; //Accessed } }
public class Circle{ int x,y; int radius; Circle(){ x=y=radius=0; } }
public class Circle{ int x,y; int radius; Circle(){ X=y=radius=0; } Circile(int x1,int y1){ x=x1; y=y1; } }
A class cannot have more than one immediate parents
public class Sphere extends Cirlce{
public class Point{
int x,int y; Point(){ x=y=0; } Point(int x1,int y1){ x=x1; y=y } public void showPoint(){ System.out.println(“X=“+x); System.out.println(“X=“+y); }
public class Point3D extends Point{ int z; Point(){ x=y=0; }
}