Looking for CS102 - Object-Oriented Programming 1 F1 - S25 test answers and solutions? Browse our comprehensive collection of verified answers for CS102 - Object-Oriented Programming 1 F1 - S25 at moodle.medtech.tn.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
In Java, each child class can have only one parent.
What is the output of the following program?
What is the purpose of upcasting in Java?
What is the output of the following code snippet?
class Person{
String name;
Person(){
System.out.println("In Person class");
}
}
class Student extends Person{
Student(){
System.out.println("In Student class");
}
int id;
public static void main(String[] a){
Student ob=new Student(); //Line 1
ob.name="abc"; //Line 2
ob.id=123;}
}
What is the output of this program
class Person{ String name; Person(){ name="John"; }}
class Employee extends Person{ int age; Employee(){ age=34; }}
class Customer extends Person{ int salary; Customer(int salary){
this.salary=salary; name="Maddy"; } public void displayDetails(){ System.out.println(name+age+salary); }}
class Account { public static void main(String[] args) { Customer c=new Customer(20000); c.displayDetails(); }}
What is the output of the following program?
class SolarSystem {}class Earth extends SolarSystem {}class Mars extends SolarSystem {}public class Moon extends Earth {public static void main(String args[]){SolarSystem s = new SolarSystem();Earth e = new Earth();Mars m = new Mars();
System.out.println(s instanceof SolarSystem);System.out.println(e instanceof Earth);System.out.println(m instanceof SolarSystem);}}
What is the output of the following program?
What is the output of the following program?
class Animal { protected String name;
protected void display() { System.out.println("I am an animal."); }}
class Dog extends Animal { protected void display() { System.out.println("I am a Dog"); } public void getInfo() { System.out.println("My name is " + name); }}
class Main { public static void main(String[] args) {
// create an object of the subclass Dog labrador = new Dog();
// access protected field and method // using the object of subclass labrador.name = "Rocky"; labrador.display();
labrador.getInfo(); }}
In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?
What is the output of this program?
class A {
int i;}
class B extends A {
int j;
void display()
{ super.i = j + 1;
System.out.println(j + " " + i); }
}
class inheritance {
public static void main(String args[]) {
B obj = new B();
obj.i=1;
obj.j=2;
obj.display(); }
}
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!