list 2 main principles of OOPS and explain them
Anonymous:
means you are also fake
Answers
Answered by
1
Here are the 2 main principles of OOPS:
(1) Inheritance
(2) Encapsulation
(1) Inheritance:
= > It is the property of deriving the new class from old one.
= > Old class is known as superclass and the new class is known as the subclass.
= > The keyword extend is used by the subclass to inherit the properties of the superclass
Ex:
class Quora
{
public void Rank()
{
System.out.println("Brainly Guru");
}
}
public class Brainly Extends Quora
{
public void SpecialRank()
{
System.out.println("Core Moderator");
}
public static void main(String args[])
{
Brainly a = new Brainly();
a.Rank();
a.SpecialRank();
}
}
Output:
Brainly Guru
Core Moderator
(2) Encapsulation:
= > Wrapping the data as a single unit.
= > It controls the way data is modified.
Ex:
class Some
{
private String student;
public String getName()
{
return student;
}
public void setName(String student)
{
this.student=student;
}
}
public class Demo
{
public static void main(String[] args)
{
Some s = new Some();
s.setName("Siddhartha");
System.out.println(s.getName());
}
}
Output:
Siddhartha.
Hope this helps!
(1) Inheritance
(2) Encapsulation
(1) Inheritance:
= > It is the property of deriving the new class from old one.
= > Old class is known as superclass and the new class is known as the subclass.
= > The keyword extend is used by the subclass to inherit the properties of the superclass
Ex:
class Quora
{
public void Rank()
{
System.out.println("Brainly Guru");
}
}
public class Brainly Extends Quora
{
public void SpecialRank()
{
System.out.println("Core Moderator");
}
public static void main(String args[])
{
Brainly a = new Brainly();
a.Rank();
a.SpecialRank();
}
}
Output:
Brainly Guru
Core Moderator
(2) Encapsulation:
= > Wrapping the data as a single unit.
= > It controls the way data is modified.
Ex:
class Some
{
private String student;
public String getName()
{
return student;
}
public void setName(String student)
{
this.student=student;
}
}
public class Demo
{
public static void main(String[] args)
{
Some s = new Some();
s.setName("Siddhartha");
System.out.println(s.getName());
}
}
Output:
Siddhartha.
Hope this helps!
Similar questions