top of page

Oops Programming Questions(JAVA)

Oops is one of the most important concepts in java, practically imagining a java application without the oops concept is nearly impossible. Oops lets you increase the efficiency of the code and through this concept you provide flexibility in your project.


Here are the question with their solutions:-


  • Create a class named 'Teacher' with String variable 'name' and integer variable 'roll_no'. Assign the value of roll_no as '11' and that of the name as "Satyam" by creating an object of the Class Teacher.


  • A class named Sum contains a parametrized method that takes two integers. Another class names Add which inherits class Sum contains a method that adds those two numbers. Print the final result in the main class by using those two classes. Also, the inputs will be given in the main class only.


  • Override a method of a class that has a method named sum with the subtraction method.


  • Make a banking software(without UI) which has four different workings which are:-Deposit, withdraw, show balance, and brach of the bank. Use abstraction, polymorphism, encapsulation, inheritance.


  • Make a program for showing a car state, object, behavior, and each of these include some sub-parts like for object it can be a sedan, hatchback, SUV, muv, etc. also for the behavior you will show car characteristics and last for the state you will show color, brand, weight, model...


  • What will be the output:-

public class Sum { 
  
 // Overloaded sum(). 
 // This sum takes two int parameters 
 public int sum(int x, int y) 
 { 
 return (x + y); 
 } 
  
 // Overloaded sum(). 
 // This sum takes three int parameters 
 public int sum(int x, int y, int z) 
 { 
 return (x + y + z); 
 } 
  
 // Overloaded sum(). 
 // This sum takes two double parameters 
 public double sum(double x, double y) 
 { 
 return (x + y); 
 } 
  
 // Driver code 
 public static void main(String args[]) 
 { 
 Sum s = new Sum(); 
 System.out.println(s.sum(10, 20)); 
 System.out.println(s.sum(10, 20, 30)); 
 System.out.println(s.sum(10.5, 20.5)); 
 } 
} 


  • What will be the output:-

class Student4{  
 int id;  
    String name;  
 //creating a parameterized constructor 
    Student4(int i,String n){  
    id = i;  
    name = n;  
    }  
 //method to display the values 
 void display(){System.out.println(id+" "+name);}  
 
 public static void main(String args[]){  
 //creating objects and passing values 
    Student4 s1 = new Student4(111,"Karan");  
    Student4 s2 = new Student4(222,"Aryan");  
 //calling method to display the values of object 
    s1.display();  
    s2.display();  
   }  
}  


  • What will be the output:-

class Student5{  
 int id;  
    String name;  
 int age;  
 
    Student5(int i,String n){  
    id = i;  
    name = n;  
    }  
 
    Student5(int i,String n,int a){  
    id = i;  
    name = n;  
    age=a;  
    }  
 void display(){System.out.println(id+" "+name+" "+age);}  
 
 public static void main(String args[]){  
    Student5 s1 = new Student5(111,"Karan");  
    Student5 s2 = new Student5(222,"Aryan",25);  
    s1.display();  
    s2.display();  
   }  
} 

  • What will be the output:-

interface CarStart  
{    
void start();
System.out.println("The car engine has been started.");    
}    
interface CarStop  
{    
void stop();
    System.out.println("The car engine has been started.");
}    
public class Car implements CarStart, CarStop  
{    
public void start()  
{  
System.out.println("The car engine has been started.");  
}    
public void stop()  
{  
System.out.println("The car engine has been stopped.");  
}    
public static void main(String args[])  
{    
Car c = new Car();    
c.start();    
c.stop();    
}  
}

  • What will be the output:-

class Bank{  
float getRateOfInterest(){return 0;}  
}  
class SBI extends Bank{  
float getRateOfInterest(){return 8.4f;}  
}  
class ICICI extends Bank{  
float getRateOfInterest(){return 7.3f;}  
}  
class AXIS extends Bank{  
float getRateOfInterest(){return 9.7f;}  
}  
class TestPolymorphism{  
public static void main(String args[]){  
Bank b;  
b=new SBI();  
System.out.println("SBI Rate of Interest: "+b.getRateOfInterest());  
b=new ICICI();  
System.out.println("ICICI Rate of Interest: "+b.getRateOfInterest());  
b=new AXIS();  
System.out.println("AXIS Rate of Interest: "+b.getRateOfInterest());  
}  
} 


More questions will be added soon, stay tuned if you like this post like comment and share with your friends, it will be of great help.




Recent Posts

See All
bottom of page