Advance Object Oriented Programming (Lecture 1) : Ms. Sehresh Khan Lecturer Numl-Rwp
Advance Object Oriented Programming (Lecture 1) : Ms. Sehresh Khan Lecturer Numl-Rwp
(Lecture 1)
Encapsulation is defined as
wrapping up of data and
information under a single
unit. In Object Oriented
Programming, Encapsulation
is defined as binding
together the data and the
functions that manipulates
them.
Access Specifiers
In C++, there are three access
specifiers:
public - members are accessible
class Main {
public static void main(String[] args)
{
Student myObj = new Student();
System.out.println(myObj.id);
//syso ctrl+space
}
}
Class Constructor
public class Student {
int id;
String name;
public Student()
{}
public Student(int i, String n)
{
id=i;
name=n;
}
}
class Main {
public static void main(String[] args)
{
Student myObj = new Student(1234, "Ahmad");
System.out.println(myObj.id);
}
}
Class member function
public class Student {
int id;
String name;
public Student()
{}
public Student(int i, String n)
{
id=i;
name=n;
}
public void show()
{
System.out.println(id);
System.out.println(name);
}
}
class Main {
public static void main(String[] args)
{
Student myObj = new Student(1234, "Ahmad");
myObj.show();
}
}
Access Specifiers
public class Student {
private int id;
private String name;
public Student()
{}
public Student(int i, String n)
{
id=i;
name=n;
}
public void show()
{
System.out.println(id);
System.out.println(name);
}
}
class Main {
public static void main(String[] args)
{
Student myObj = new Student(1234, "Ahmad");
myObj.show();
}
}