OOPS — Problems & Solutions
3 min readAug 18, 2026
Print Student Information — link
class Student
{
private string name;
private int age;
private int marks[] = new int[3];
Student(String name, int Age, int Marks[])
{
name = Name;
age = Age;
marks[0] = Marks[0];
marks[1] = Marks[1];
marks[2] = Marks[2];
}
public string get_name()
return name;
public int get_age()
return age;
public int get_maximum()
{
int max = Marks[];
if(marks[1] > marks[0] && marks[1] >= marks[2])
max = marks[1];
if(marks[2] >= marks[0] && marks[2] >= marks[1])
max = marks[2];
return max;
}
}
public class Main
{
public static void main(String[] args)
{
int marks[] = new int[3];
marks[0] = 80;
marks[1] = 85;
marks[2] = 87;
Student obj = new Student(Name: "Saksham", Age: 23, marks);
System.out.println(obj.get_name());
System.out.println(obj.get_age());
System.out.println(obj.get_maximum());
}
}Output of The Number of Objects — link
class SchoolMember
{
string name;
static int num;
SchoolMember() { }
class Teacher extends SchoolMember
{
Teacher() { num++; }
}
class Student extends SchoolMember
{
Student() { num++; }
}
}
public class Main
{
public static void main(String[] args)
{
Student obj = new Student();
Student obj1 = new Student();
System.out.println(obj.num);
System.out.println(obj1.num);
System.out.println(SchoolMember.num);
}
}Using the transportation method — link
class VehicleGet Kirti Konka’s stories in your inbox
Join Medium for free to get updates from this writer.
{
int speed, acc, time, vol;
Vehicle(int s, int a, int t, int v)
{
speed = s;
acc = a;
time = t;
vol = v;
}
void move()
{
System.out.println("Speed = " + speed);
System.out.println("Acceration = " + acc);
System.out.println("Time = " + time);
}
void setSpeed(int initialSpeed)
{
speed = initalSpeed;
}
void speedUp()
{
speed = speed + acc * time;
}
void speedDown()
{
speed = speed - acc * time;
if(speed < 0)
speed = 0;
}
}
public class Main
{
public static void main(String args[])
{
Vehicle obj = new Vehicle(5,2,2,10);
obj.setSpeed(10);
obj.move();
obj.speedUp();
obj.move();
obj.speedDown()
obj.move();
}
}
Perimeter and area of Square — link
class Rectangle
{
int b, l;
int perimeter()
return 2 * (l + b);
int area()
return l * b;
}
class Square extends Rectangle
{
Square() { }
Square(int len)
super(len,len);
}
public class Main
{
public static void main(String[] args)
{
Square obj = new Square(5);
System.out.println(obj.perimeter());
System.out.println(obj.area());
}
}Performance of multiple instruments — link
class Instrument
{
void makeNoise()
{
System.Out.Println("Instrument makes beautiful noise");
}
}
class Erhu extends Instrument
{
void makeNoise()
{
System.Out.Println("Erhu is good to hear");
}
}
class Piano extends Instrument
{
void makeNoise()
{
System.Out.Println("Piano is pleasing");
}
}
class Violin extends Instrument
{
void makeNoise()
{
System.Out.Println("Violin is pleasing");
}
}
public class Main
{
public static void main(String arg[])
{
Erhu obj = new Ehru();
Piano obj1 = new Piano();
Violin obj2 = new Violin();
obj.makeNoise();
obj1.makeNoise();
obj2.makeNoise();
}
}Different Drinking Experience — link
interface Drinks
{
void getName();
void drinkFeeling();
}
class Water implements Drinks
{
public void getName()
{
System.Out.Println("Water");
}
public void drinkFeeling()
{
System.Out.Println("Water is great");
}
}
class Milk implements Drinks
{
public void getName()
{
System.Out.Println("Milk");
}
public void drinkFeeling()
{
System.Out.Println("Milk is good");
}
}
public class Main
{
public static void main(String arg[])
{
Water obj1 = new Water();
Milk obj2 = new Milk();
obj1.getName();
obj1.drinkFeeling();
obj2.getName();
obj2.drinkFeeling();
}
}







