public class Puppy { int puppyAge; public Puppy (String name) { // This constructor has one parameter, name. System.out.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

public class Puppy { int puppyAge; public Puppy (String name) { // This constructor has one parameter, name. System.out.

Post by answerhappygod »

Public Class Puppy Int Puppyage Public Puppy String Name This Constructor Has One Parameter Name System Out 1
Public Class Puppy Int Puppyage Public Puppy String Name This Constructor Has One Parameter Name System Out 1 (51.03 KiB) Viewed 44 times
Public Class Puppy Int Puppyage Public Puppy String Name This Constructor Has One Parameter Name System Out 2
Public Class Puppy Int Puppyage Public Puppy String Name This Constructor Has One Parameter Name System Out 2 (51.03 KiB) Viewed 44 times
public class Puppy { int puppyAge; public Puppy (String name) { // This constructor has one parameter, name. System.out.println("Name chosen is :" + name ); } public void setAge(int age) ( puppyAge = age; } public int getAge() { System.out.println("Puppy's age is :" + puppyAge ); return puppyAge; } public static void main(String [largs) ( /* Object creation */ Puppy myPuppy new Puppy("tommy" ); /* Call class method to set puppy's age */ my Puppy.setAge ( 2 ); /* Call another class method to get puppy's age */ myPuppy.getAge(); /* You can access instance variable as follows as well */ System.out.println("Variable Value : syPuppy-puppyAge
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply