62 560
Assignments Done
98,8%
Successfully Done
In June 2018

Answer to Question #3477 in Java | JSP | JSF for Y mukundareddy

Question #3477
(3) Write a program to declare some int variables and string variables as protected and public and access them in another class?
Expert's answer
public class Task7
{
public static void main(String[] args)
{
& Cat kitten = new Cat(1, "Murka");
& kitten.printInfo();
}
}

// The super class that implements one public variable and one protected variable
// These variables would be used in the child class
class Animal
{
public int age;
protected String name;

Animal(int pAge, String pName)
{
& age = pAge;
& name = pName;
}

public void printInfo()
{
}
}

// The derived class access the variables of the superClass
class Cat extends Animal
{
Cat(int pAge, String pName)
{
& super(pAge, pName);
}

public void printInfo()
{
& // The access to the public int variable and protected string variable
& System.out.print("Cat, it's age is " + age + " years and it's name is " + name);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions