0% found this document useful (0 votes)
28 views11 pages

Ayush Java 2

The document contains code snippets and output related to Java programming concepts like classes, objects, constructors, inheritance, polymorphism, interfaces, and access modifiers. It provides examples and code to demonstrate these Java concepts across multiple pages.

Uploaded by

Okby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Ayush Java 2

The document contains code snippets and output related to Java programming concepts like classes, objects, constructors, inheritance, polymorphism, interfaces, and access modifiers. It provides examples and code to demonstrate these Java concepts across multiple pages.

Uploaded by

Okby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Vidhyadeep insti. Of com. & info.

Technology, anita
(kim)

Name :- RAMANI AYUSH

EN No :- E21110403000110108

Sub :- java (Assignment - 2)

Sem :- S.Y B.C.A Sem-4

PAGE NO:-1 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

P1AREAOFCIRCLEANDRECTANGLE

*Areaofcircle

publicclassGFG{
publicstaticvoidmain(String[]args)
{
intradius; doublepi=3.142,area;
radius=5; area=pi*radius*radius;

System.out.println("Areaofcircleis:"+area);
}
}

OUTPUT:-

*Areaofrectangle

publicclassrectangle{
publicstaticvoidmain(Stringargs[])
{
intwidth=5; intheight=10;
intarea=width*height;
System.out.println("Areaofrectangle="+area);
}
}

OUTPUT:-

PAGE NO:-2 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

P2HEIGHTWIDTHANDDEPTHOFBOX

importjava.util.Scanner;

classBox{ inthegiht; intwidth;

intdepth;

Box(inta,intb,intc)

hegiht=a; width=b; depth=c;

intcalvolume()

returnhegiht*width*depth;

publicclassMain{ publicstaticvoidmain(Stringargs[])

inta,b,c;

Scannerput=newScanner(System.in);
System.out.println("ENTERHEIGHTWIDTHANDDEPTH");

PAGE NO:-3 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

a=put.nextInt(); b=put.nextInt(); c=put.nextInt(); BoxA=newBox(a,b,c);

intvolume=A.calvolume();

System.out.print("VOLUMEOFBOX="+volume);

OUTPUT:-

P3Parameterizedconstructors publicclassTest{

Stringval;

Test(Stringval){ this.val=val;

publicstaticvoidmain(Stringargs[]){

Testobj=newTest("ABDULLAH");

System.out.println(obj.val);

OUTPUT:-

PAGE NO:-4 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

P4demonstrateconstructoroverloading

publicclassStudent{ //instancevariablesoftheclass

intid;

Stringname;

Student(){

System.out.println("thisadefaultconstructor");

Student(inti,Stringn){ id=i;

name=n;

publicstaticvoidmain(String[]args){

//objectcreation

Students=newStudent();

System.out.println("\nDefaultConstructorvalues:\n");

System.out.println("StudentId:"+s.id+"\nStudentName:"+s.name);

System.out.println("\nParameterizedConstructorvalues:\n");

Studentstudent=newStudent(10,"ABDULLAH");

System.out.println("StudentId:"+student.id+"\nStudentName:"+student.name);

PAGE NO:-5 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

OUTPUT:-

accessmodifier

*public publicclassmain{ staticvoidmyMethod(){

System.out.println("Abdullah");

publicstaticvoidmain(String[]args)

{ myMethod();

Output:-

PAGE NO:-6 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

*private publicclassmain{ privatestaticvoidmyMethod(){

System.out.println("Abdullah");

publicstaticvoidmain(String[]args)

{ myMethod();

Output:-

*protected classAnimal{

//protectedmethod protectedvoiddisplay(){

System.out.println("Iamanking");

classkingextendsAnimal{ publicstaticvoidmain(String[]args){

//createanobjectofDogclass kingk=newking();

//accessprotectedmethod k.display();

PAGE NO:-7 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

Output:-

Polymorphism classBank{

floatgetRateOfInterest(){return0;}

classSBIextendsBank{ floatgetRateOfInterest(){return8.4f;}

classICICIextendsBank{ floatgetRateOfInterest(){return7.3f;}

classAXISextendsBank{ floatgetRateOfInterest()

{return9.7f;}

classTestPolymorphism{ publicstaticvoidmain(Stringargs[]){

Bankb; b=newSBI();

System.out.println("SBIRateofInterest:"+b.getRateOfInterest()); b=newICICI();

System.out.println("ICICIRateofInterest:"+b.getRateOfInterest()); b=newAXIS();

System.out.println("AXISRateofInterest:"+b.getRateOfInterest());

OUTPUT:-

PAGE NO:-8 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

staticmember publicclassMyClass{

publicstaticvoidsample(){

System.out.println("Abdullah");

publicstaticvoidmain(Stringargs[]){ MyClass.sample();

OUTPUT:-

*STATICBLOCK publicclassMyClass{

static{

System.out.println("Hellothisisastaticblock");

publicstaticvoidmain(Stringargs[]){

System.out.println("Thisismainmethod");

PAGE NO:-9 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

OUTPUT:-

INTERFACE

interfaceprintable{ voidprint();

classA6implementsprintable{ publicvoidprint()
{System.out.println("Abdullah");}

publicstaticvoidmain(Stringargs[]){ A6obj=newA6(); obj.print();

OUTPUT:-

Inheritance

classEmployee{ floatsalary=40000;

classProgrammerextendsEmployee{ intbonus=10000;

publicstaticvoidmain(Stringargs[]){ Programmerp=newProgrammer();

PAGE NO:-10 SUB:-JAVA PREP BY:-


AYUSH
Vidhyadeep insti. Of com. & info. Technology, anita
(kim)

System.out.println("Programmersalaryis:"+p.salary);

System.out.println("BonusofProgrammeris:"+p.bonus);

OUTPUT:-

PAGE NO:-11 SUB:-JAVA PREP BY:-


AYUSH

You might also like