• iconJava Online Training In Andhra Pradesh and Telangana
  • icon9010519704

Opening Hours :7AM to 9PM

Data Abstraction in Java


Data Abstraction:
Hiding of implementation or hiding of attributes from the unauthorized behavior from the class is known as Data Abstraction.
In java language Data Abstraction can be achieved using 'class' keyword.
as per as java language concent hiding of variables from the the unauthorized method of class is known as Data Abstraction.The main aim advantage with this security can be provide for the data.
Note: Once encapsulation can be apply the 'Data Abstraction' automatically applied.

Constructors In Java


Constructor
Constructor is a non-static method of a class.Which is used to initilize the values.
Syntax:

Classname(list of parameters / no parameters)
{
    ....
    ....
}

In the above syntax constructor name always class name.
In java language these constructers are classisfied into following types
1.Noparametarized Constructor
2.Parametarized Constructor
3.Default Constructor

1.NoParametarized Constructor:
If any Constructor signature does not contain parameters is known as NoParametarized Constructor
Syntax:

Classname()
{
    ....
    ....
}


2.Parametarized Constructor:

If any Constructor signature contains List of parameters is known as Parametarized Constructor
Syntax:

Classname(Datatype Variable1,Datatype Variable2, ....)
{
    ....
    ....
}


3.Default Constructor:
If any program does not contain any Userdefined Constructor the JVM creates one constructor is called Default Constructor.
Syntax:

Classname()
{
//Nobody
}



Based on the Constructors these methods are classified into following types
1.No Parametarized Constructor with No return type with no Parametarized Method
2.No Parametarized Constructor with No return type with Parametarized Method
3.No Parametarized Constructor with return type with no Parametarized Method
4.No Parametarized Constructor with return type with Parametarized Method
5.Parametarized Constructor with No return type with no Parametarized Method
6.Parametarized Constructor with No return type with Parametarized Method
7.Parametarized Constructor with return type with no Parametarized Method
8.Parametarized Constructor with return type with Parametarized Method

1. No Parametarized Constructor with No return type with no Parametarized Method
2. No Parametarized Constructor with No return type with Parametarized Method
3. No Parametarized Constructor with return type with no Parametarized Method
4. No Parametarized Constructor with return type with Parametarized Method
5. Parametarized Constructor with No return type with no Parametarized Method
6. Parametarized Constructor with No return type with Parametarized Method
7. Parametarized Constructor with return type with no Parametarized Method
8. Parametarized Constructor with return type with Parametarized Method

1. No Parametarized Constructor with No return type with no Parametarized Method

class MaxNum
{
int x,y;
MaxNum()
{
x=10;
y=20;
}
void max()
{
if(x>y)
{
System.out.println("X is Max Number");
}
else
{
System.out.println("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum();
m.max();
}
}


Output:
Y is Max Number
2. No Parametarized Constructor with No return type with Parametarized Method

class MaxNum
{
int x,y;
MaxNum()
{
x=10;
y=20;
}
void max(int a,int b)
{
if(x>y)
{
System.out.println("X is Max Number");
}
else
{
System.out.println("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum();
m.max(100,200);
}
}


Output:
Y is Max Number
3. No Parametarized Constructor with return type with no Parametarized Method

class MaxNum
{
int x,y;
MaxNum()
{
x=10;
y=20;
}
String max()
{
if(x>y)
{
return("X is Max Number");
}
else
{
return("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum();
String s=m.max();
SYstem.out.println(s);
}
}


Output:
Y is Max Number
4. No Parametarized Constructor with return type with Parametarized Method

class MaxNum
{
int x,y;
MaxNum()
{
x=10;
y=20;
}
String max(int a,int b)
{
if(x>y)
{
return("X is Max Number");
}
else
{
return("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum();
String s=m.max(100,200);
SYstem.out.println(s);
}
}


Output:
Y is Max Number
5. Parametarized Constructor with No return type with no Parametarized Method

class MaxNum
{
int x,y;
MaxNum(int p,int q)
{
x=10; // or x=p;
y=20; // or y=q;
}
void max()
{
if(x>y)
{
System.out.println("X is Max Number");
}
else
{
System.out.println("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum(1000,2000);
m.max();
}
}


Output:
Y is Max Number
6. Parametarized Constructor with No return type with Parametarized Method

class MaxNum
{
int x,y;
MaxNum(int p,int q)
{
x=10; // or x=p;
y=20; // or y=q;
}
void max(int a,int b)
{
if(x>y)
{
System.out.println("X is Max Number");
}
else
{
System.out.println("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum(1000,2000);
m.max(100,200);
}
}


Output:
Y is Max Number
7. Parametarized Constructor with return type with no Parametarized Method

class MaxNum
{
int x,y;
MaxNum(int p,int q)
{
x=10; // or x=p;
y=20; // or y=q;
}
String max()
{
if(x>y)
{
return("X is Max Number");
}
else
{
return("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum(1000,2000);
String s=m.max();
System.out.println(s);
}
}


Output:
Y is Max Number
8. Parametarized Constructor with return type with Parametarized Method

class MaxNum
{
int x,y;
MaxNum(int p,int q)
{
x=10; // or x=p;
y=20; // or y=q;
}
String max(int a,int b)
{
if(x>y)
{
return("X is Max Number");
}
else
{
return("Y is Max Number");
}
}
}
class Main
{
public static void main(String args[])
{
MaxNum m=new MaxNum(1000,2000);
String s=m.max(100,200);
System.out.println(s);
}
}


Output:
Y is Max Number