Your SlideShare is downloading. ×
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Assignment of java
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Assignment of java

440

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
440
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
40
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Inheritance: Whenever we create a new class with the help of the existing class in such a way that the new class can inherit the all features of the previous/old class and all the public member of the old class become the public member of the new class and all the private member of the old class become the private member of the new class. Old class is also called parent or base class and the new class is also called child or derived class. Program: class province { String city,town,village; Scanner in =new Scanner(System.in); void get() { System.out.println(“Enter the name of city”); city=in.nextLine(); System.out.println(“Enter the name of town”); town=in.nextLine(); System.out.println(“Enter the name of village”); village=in.nextLine(); } void display() { System.out.println(“name of city=”+city); System.out.println(“name of town=+town”); System.out.println(“name of village=”+village); } }
  • 2. class population extends province { int nom,now; Scanner in =new Scanneer(System.in); void get1() { System.out.println(“enter the number of men”); nom=in.nextInt(); System.out.println(“enter the number of women”); now=in.nextInt(); } void diaplay1() { System.out.println(“the number of men are=”+nom); System.out.println(“the number of men are=”+now); } } class Appopulation { puplic static void main(String args[]) { population P1=new population(); P1.get(); P1.get1(); P1.display(); P1.display1(); } }
  • 3. Multilevel Inheritance: When we create more than one child classes of a base/super class, this is called multilevel inheritance. Program: class book { String name,author,prise; Scanner in =new Scanner(System.in); void get() { System.out.println(“Enter the name of the book”); name=in.nextLine(); System.out.println(“Enter the name of author”); author=in.nextLine(); System.out.println(“Enter the price of book”); price=in.nextLine(); } void display() { System.out.println(“name of the book=”+name); System.out.println(“author of the book=”+author); System.out.println(“prise of the book=”+prise); } } class librarybook extands book
  • 4. { int quantity,tcost,num; Scanner in =new Scanner(System.in); void input() { System.out.println(“enter the quantity of book”); quantity=in.nextInt(); System.out.println(“enter the total cost of book”); tcost=in.nextInt(); System.out.println(“enter the number of book”); num=in.nextInt(); } void output() { System.out.println(“quantity of books=”+book); System.out.println(“total cost of books=”+tcost); System.out.println(“number of books=”+num); } } class book issue extends library book { String person,date; Scanner in =new Scanner(System.in); void input1() { System.out.println(“enter the name of person”); person=in.nextLine(); System.out.println(“enter the date of issue”); date=in.nextLine();
  • 5. } void output1() { System.out.println(“person who issue book=”+person); System.out.println(“date of issue of book=”+date); } } class Apbook issue { puplic static void main(String args[]) { book issue bi=new book issue(); bi.get(); bi.display(); bi.input(); bi.output(); bi.input1(); bi.output1(); } } Super key word: A super key word is used in java for tow purposes,  It is used to access the member of parent class that is overridden by the child class.  It is also used to call the constructor of the super class in the child class.
  • 6. Important point: Whenever a base class has a parametric constructor then its all child classes must have the parametric constructor. Program: class W { int A,B,C; W(int A1,intB1,intC1) { A=A1,B=B1,C=C1 } void sum() { R=A+B+C; } void display() { System.out.println(“R”); } } class X extends W { int D,E; X(intA1,intB1,intC1,intD1,intE1)
  • 7. { Super(A1,B1,C1); D=D1,E=E1; } void sum() { R=A+B+C+D*E; } } class Y extends X { int F; Y(int A1,intB1,intC1,intD1,intE1,intF1); { Super(int A1,intB1,intC1,intD1,intE1); F=F1; } void sum2() { R=A+B+C+(D*E)+F; } } class Z extends Y { int G; X(intA1,intB1,intC1,intD1,intE1,intF1,intG1); { Super(intA1,intB1,intC1,intD1,intE1,intF1); G=G1;
  • 8. } void sum3() { R=A+B+C+D+E+F+G; } } class ApZ { public static void main(String args[]) { Z S=new Z(1,2,3,4,5,6,7); S.sum(); S.dispaly(); S.sum1(); S.dispaly(); S.sum2(); S.dispaly(); S.sum3(); S.dispaly(); } } Dynamic method dispatch: Compile time bounding: During the compile time bounding all the static work is completed like int S,S=5; etc
  • 9. Execute time bounding: All the input work is done during the execute time bounding like num=in.nextInt();etc Method overriding: When two methods have same name and function in different classes then it is called method overriding. Program: class A { int a,b; void get() { The body of the get method } } class B extends A { int b,c,d; void get() { The body of the second get method } } class ApB
  • 10. { public static void main(String args[]) B b1=new B(); b1.get(); } } Final key word : A final key word is used to make a variable constant like final int a=10;  The value of this variable cannot change throughout the program. We can also use the final key word with methods as well as with classes like final class XYZ final void get();  A method cannot be overwritten when it is declared as final.  Similarly a class cannot be inherited when it is declared as final. In other words we cannot make the child classes of a final declared class. Abstract class: A class which contain at least one method without body then this class is declared as abstract class.  The object of the abstract class cannot be created.  Whenever we have an abstract class then we can use it only by inheritance. Abstract Constructor : Abstract constructor does not exist in the class; you have to create concrete constructor which have complete body.
  • 11. Abstract Static methods: Abstract static methods cannot work in the abstract class. Program: abstract class intor { String nam,add; Scanner in =new Scanner (System,in); void get() { System.out.println(“enter the name of the student”); nam=in.nextLine(); System.out.println(“enter the address of the student”); add=in.nextLine(); } abstract void regist(); abstrce void display(); } } class show extends intro { int rnum,rollnum; void regist() { System.out.println(“enter the registration number of the student”); rnum=in.nInt(); System.out.println(“enter the roll number of the student”); rollnum=in.nextInt();
  • 12. } void display() { System.out.println(“the name of the student is=”+nam); System.out.println(“the address of the student is=”+add); System.out.println(“the registration number of the student is=”+rnum); System.out.println(“the roll number of the student is=”+rollnum); } } class Apshow { public static void main(String args[]) { show S1=new show(); S1.get(); S1.regist(); S1.display(); } } Very Important Note: Constructors are called from bottom to top and execution of constructors is start from top to bottom.

×