Core Java Practial
Core Java Practial
___________________________________________________
1) package com.oops;
int StudentId;
String StudentName;
String StudentCity;
// above are Data: data members or instance variable.
}
public void ShowFullDetails()
{
System.out.println("My name is " +StudentName);
System.out.println("MY ID IS" +StudentId);
System.out.println("MY CITY IS" +StudentCity);
}
************************************************
WITH THE HELP OF ABOVE WE CAN CREATE THE MANY OBJECTS ABOVE ARE (LIKE TEMPLATE)
*********************************************************************************
package com.oops;
st1.StudentId=123;
st1.StudentCity="raj";
st1.study(); //if we run is get output where we mention in stud class
st1.ShowFullDetails();
System.out.println("*******************************");
Stud st2= new Stud(); //with the help of
object(like //
st1,st2,st3...) we can create many stud info
___________________________________________________________________________________
_______________----
2) BANKING info
**************************************************************
public class Bank {
long CustACNOL;
String CustName;
double CustBalance;
}
public void Custdetails(){
System.out.println("my name is" +CustName);
System.out.println(" my ACCOUNT NO is " +CustACNOL);
System.out.println( " my balnce is " +CustBalance);
}
___________________________________________________________________________________
___________________
}
___________________________________________________________________________________
________________
*/
____________________________________________________________--
3) package com.oops;
int StudentId;
String StudentName;
String StudentCity;
public Stud()
{
System.out.println("creating object"); // pass const run it
}
}
public void ShowFullDetails()
{
System.out.println("My name is " +StudentName);
System.out.println("MY ID IS" +StudentId);
System.out.println("MY CITY IS" +StudentCity);
}
}
___________________________________________________________________________________
_
constructor overloading
defining multiple const within a same class called const overloading
*******************************************************************
package com.oops;
int StudentId;
String StudentName;
String StudentCity;
public Stud()
{
System.out.println("creating object");
}
public Stud(int st1){
System.out.println("parameterize const");
}
}
public void ShowFullDetails()
{
System.out.println("My name is " +StudentName);
System.out.println("MY ID IS" +StudentId);
System.out.println("MY CITY IS" +StudentCity);
}
}
______________________________________________________________________________
package com.oops;
st1.StudentId=123;
st1.StudentCity="raj";
st1.study();
st1.ShowFullDetails();
System.out.println("*******************************");
Stud st2= new Stud(12); //overloading //with
the help of //object(like
st1,st2,st3...) we can create many stud
//information
}
___________________________________________________________________________________
________
4) package com.oops;
int StudentId;
String StudentName;
String StudentCity;
public Stud()
{
System.out.println("creating object");
}
public Stud(int st1){
System.out.println("parameterize const");
}
public Stud(int i,String n, String C){ // passing parameter
StudentId=i;
StudentName=n;
StudentCity=C;
}
}
public void ShowFullDetails()
{
System.out.println("My name is " +StudentName);
System.out.println("MY ID IS" +StudentId);
System.out.println("MY CITY IS" +StudentCity);
}
}
___________________________________________________________________________
package com.oops;
Stud st1;
st1 =new Stud( 74 ,"RAJ","MUMBAI");
st1.study();
st1.ShowFullDetails();}}
___________________________________________________________________________________
____
**********************************************************************************
_______________________________________________________________________________----
--
}
public MOM(String n,int p, String c){
PENname=n;
PENprice=p;
Pencolor=c;
}
public void showdetails()
{
System.out.println("my pen name is"+PENname);
System.out.println("my pen PRICE"+PENprice);
System.out.println("MY PEN COLOR"+Pencolor);
}
___________________________________________________________________________________
______________
6) /* METHOD overloading:
having multiple method in same class with same name
num of argument different
types of argument different
order of argument may differnt
*/***************************************************************************
}
public MOM(String n,int p, String c){
PENname=n;
PENprice=p;
Pencolor=c;
}
public void showdetails()
{
System.out.println("my pen name is"+PENname);
System.out.println("my pen PRICE"+PENprice);
System.out.println("MY PEN COLOR"+Pencolor);
}
public void showdetails(float f){
}
}
__________________________________________________________________________________
public class object {
public static void main(String[] args) {
MOM m1=new MOM("cello",74,"red");
m1.showdetails();
}
}
___________________________________________________________________________________
_____
7)
/* this keyword refer current invoking object
used to calling current class constructor from in side different constructor
*/
*****************************************************************************
public class THISOBJ {
public static void main(String[] args) {
THISKEYWORD T= new THISKEYWORD(10);
T.show();
}
}
**************************************************************************
8)
public class THISKEYWORD {
int x; // instance variable
public THISKEYWORD(int x){ // local variable
x=x; // run out will b 0 not define becoz it consider local variable n instance
are same
this.x =x; // with help of this we can defin both x are hv diff function
nnow we get 10 which we pass
means suppose dog is child class also called subclass ,dervied class, who work to
take function(like eat ,color) from parents class
Animal is parent class here work to give function is also called Super class and
base class.
child can make his properties /function and also take from animal i.e. from parents
class
*/
***************************88888888888888888********************************
package com.inherit;
___________________________________________________________________________
package com.inherit;
10)
**************************************
and
*********************************
package SingleInherit;
___________________________________________________________________________________
public class C extends B{
public void methodC()
{
System.out.println("multilevel");
}
}
}
__________________________________________________________________________________-
11)